From b4a6388f2c77414e803aea693b6552da5d21920a Mon Sep 17 00:00:00 2001 From: burki Date: Sat, 7 May 2022 22:34:34 +0200 Subject: [PATCH 1/6] Update README.md Fix typo --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 15e771c8..4caec48a 100644 --- a/README.md +++ b/README.md @@ -178,7 +178,7 @@ Since version 2.1 you have also the possibility to apply a filter so that just s ```php

This a wise sentence render($data, "citation", json_decode('[{"id":"item-1"}]')); ?>.

-

This is the most wise setence +

This is the most wise sentence render($data, "citation", json_decode('[{"id":"item-1"},{"id":"ITEM-2"}]')); ?>.

``` @@ -391,4 +391,4 @@ $ composer test * [Stud.IP](https://github.com/studip/studip) * [bibliography Plugin for DokuWiki](https://github.com/gyger/dokuwiki-bibliography) * [ldbase_citations (Plugin for LDbase)](https://github.com/ldbase/ldbase_citations) -* [Citations - (Drupal module)](https://github.com/fsulib/citations) \ No newline at end of file +* [Citations - (Drupal module)](https://github.com/fsulib/citations) From 14ca3b321f52d818a0c3d2f08b4b946876051fc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ttger?= Date: Sat, 7 May 2022 22:57:23 +0200 Subject: [PATCH 2/6] Solves issue #105 --- composer.json | 6 +- src/Styles/TextCaseTrait.php | 3 - src/Util/StringHelper.php | 40 ++- .../humans/bugfix-github-105.txt | 325 ++++++++++++++++++ tests/src/BugfixTest.php | 5 + tests/src/CiteProcTest.php | 2 +- tests/src/ContextTest.php | 2 +- tests/src/Locale/LocaleTest.php | 2 +- tests/src/Rendering/GroupTest.php | 2 +- tests/src/Rendering/Name/NamesTest.php | 2 +- tests/src/Rendering/NumberTest.php | 2 +- tests/src/Rendering/TextTest.php | 2 +- tests/src/Style/MacroTest.php | 2 +- tests/src/Util/PageHelperTest.php | 2 +- 14 files changed, 367 insertions(+), 30 deletions(-) create mode 100644 tests/fixtures/basic-tests/processor-tests/humans/bugfix-github-105.txt diff --git a/composer.json b/composer.json index b73d28b2..1efe2677 100644 --- a/composer.json +++ b/composer.json @@ -27,16 +27,16 @@ } }, "require": { - "seboettg/collection": "^2.1", + "seboettg/collection": ">=3.0", "myclabs/php-enum": "^1.5", "ext-simplexml": "*", "ext-json": "*", - "php": ">=7.1", + "php": ">=7.3", "ext-mbstring": "*" }, "require-dev": { "php-coveralls/php-coveralls": "^1", - "phpunit/phpunit": "^7.5", + "phpunit/phpunit": "^8.5", "squizlabs/php_codesniffer": "^3.5", "phpmd/phpmd": "^2.8" }, diff --git a/src/Styles/TextCaseTrait.php b/src/Styles/TextCaseTrait.php index 3d2840f7..420fb5b8 100644 --- a/src/Styles/TextCaseTrait.php +++ b/src/Styles/TextCaseTrait.php @@ -27,9 +27,6 @@ trait TextCaseTrait protected function initTextCaseAttributes(SimpleXMLElement $node) { foreach ($node->attributes() as $attribute) { - /** - * @var string $name - */ $name = $attribute->getName(); $value = (string) $attribute; diff --git a/src/Util/StringHelper.php b/src/Util/StringHelper.php index c3bb53ee..86685aac 100644 --- a/src/Util/StringHelper.php +++ b/src/Util/StringHelper.php @@ -11,6 +11,7 @@ namespace Seboettg\CiteProc\Util; use Seboettg\CiteProc\CiteProc; +use Seboettg\Collection\ArrayList; /** * Class StringHelper @@ -89,24 +90,33 @@ public static function capitalizeAll($text) */ public static function capitalizeForTitle($titleString) { + if (strlen($titleString) == 0) { + return ""; + } if (preg_match('/(.+[^\<\>][\.:\/;\?\!]\s?)([a-z])(.+)/', $titleString, $match)) { $titleString = $match[1].StringHelper::mb_ucfirst($match[2]).$match[3]; } - - $wordArray = explode(" ", $titleString); - - array_walk($wordArray, function (&$word) { - $words = explode("-", $word); - if (count($words) > 1) { - array_walk($words, function (&$w) { - $w = StringHelper::keepLowerCase($w) ? $w : StringHelper::mb_ucfirst($w); - }); - $word = implode("-", $words); - } - $word = StringHelper::keepLowerCase($word) ? $word : StringHelper::mb_ucfirst($word); - }); - - return implode(" ", array_filter($wordArray)); + $pattern = "/(\s|\/)/"; + if (!preg_match($pattern, $titleString, $matches)) { + return StringHelper::mb_ucfirst($titleString); + } + $delimiter = $matches[1]; + $wordArray = preg_split($pattern, $titleString); //explode(" ", $titleString); + + $wordList = new ArrayList(...$wordArray); + return $wordList + ->map(function(string $word) { + $wordParts = explode("-", $word); + if (count($wordParts) > 1) { + $casedWordParts = []; + foreach ($wordParts as $w) { + $casedWordParts[] = StringHelper::keepLowerCase($w) ? $w : StringHelper::mb_ucfirst($w); + } + $word = implode("-", $casedWordParts); + } + return StringHelper::keepLowerCase($word) ? $word : StringHelper::mb_ucfirst($word); + }) + ->collectToString($delimiter); } /** diff --git a/tests/fixtures/basic-tests/processor-tests/humans/bugfix-github-105.txt b/tests/fixtures/basic-tests/processor-tests/humans/bugfix-github-105.txt new file mode 100644 index 00000000..e9060630 --- /dev/null +++ b/tests/fixtures/basic-tests/processor-tests/humans/bugfix-github-105.txt @@ -0,0 +1,325 @@ +>>===== MODE =====>> +bibliography +<<===== MODE =====<< + +>>===== RESULT =====>> +
+
1.
Braintree/Braintree_php. Braintree; 2021. Accessed June 21, 2021. https://github.com/braintree/braintree_php/blob/d6ce80f7f54abe9972d577173343d1975bc49e77/lib/Braintree/Digest.php
+
+<<===== RESULT =====<< + +>>===== CSL =====>> + + +<<===== CSL =====<< + +>>===== INPUT =====>> +[ + { + "URL": "https://github.com/braintree/braintree_php/blob/d6ce80f7f54abe9972d577173343d1975bc49e77/lib/Braintree/Digest.php", + "abstract": "Braintree PHP library", + "accessed": { + "date-parts": [ + [ + "2021", + 6, + 21 + ] + ] + }, + "genre": "PHP", + "id": "item-1", + "issued": { + "date-parts": [ + [ + "2021", + 6, + 21 + ] + ] + }, + "note": "original-date: 2010-02-26T00:46:58Z", + "publisher": "Braintree", + "source": "GitHub", + "title": "braintree/braintree_php", + "type": "book" + } +] +<<===== INPUT =====<< diff --git a/tests/src/BugfixTest.php b/tests/src/BugfixTest.php index 2c866305..ed5b256a 100644 --- a/tests/src/BugfixTest.php +++ b/tests/src/BugfixTest.php @@ -140,4 +140,9 @@ public function testBugfixGithub95() { $this->runTestSuite('bugfix-github-95'); } + + public function testBugfixGithub105() + { + $this->runTestSuite("bugfix-github-105"); + } } diff --git a/tests/src/CiteProcTest.php b/tests/src/CiteProcTest.php index f3d1b986..e0d0be64 100644 --- a/tests/src/CiteProcTest.php +++ b/tests/src/CiteProcTest.php @@ -26,7 +26,7 @@ class CiteProcTest extends TestCase */ private $citeProc; - public function setUp() + public function setUp(): void { //parent::setU } diff --git a/tests/src/ContextTest.php b/tests/src/ContextTest.php index 934b1d80..758eff48 100644 --- a/tests/src/ContextTest.php +++ b/tests/src/ContextTest.php @@ -28,7 +28,7 @@ class ContextTest extends TestCase */ private $context; - public function setUp() + public function setUp(): void { $style = StyleSheet::loadStyleSheet("din-1505-2"); $this->citeProc = new CiteProc($style, "de-DE"); diff --git a/tests/src/Locale/LocaleTest.php b/tests/src/Locale/LocaleTest.php index d5b87c65..d17febfe 100644 --- a/tests/src/Locale/LocaleTest.php +++ b/tests/src/Locale/LocaleTest.php @@ -29,7 +29,7 @@ public function testFilterTerms() static::assertEquals("o. J.", $a2->{'single'}); } - protected function setUp() + protected function setUp(): void { $this->object = new Locale("de-DE"); } diff --git a/tests/src/Rendering/GroupTest.php b/tests/src/Rendering/GroupTest.php index 3a3ffce8..b1523a04 100644 --- a/tests/src/Rendering/GroupTest.php +++ b/tests/src/Rendering/GroupTest.php @@ -21,7 +21,7 @@ class GroupTest extends TestCase private $data = "{\"title\":\"Ein Buch\", \"URL\":\"http://foo.bar\"}"; - public function setUp() + public function setUp(): void { parent::setUp(); // TODO: Change the autogenerated stub $context = new Context(); diff --git a/tests/src/Rendering/Name/NamesTest.php b/tests/src/Rendering/Name/NamesTest.php index 59b1414f..d4c10533 100644 --- a/tests/src/Rendering/Name/NamesTest.php +++ b/tests/src/Rendering/Name/NamesTest.php @@ -17,7 +17,7 @@ class NamesTest extends TestCase use TestSuiteTestCaseTrait; - public function setUp() + public function setUp(): void { parent::setUp(); } diff --git a/tests/src/Rendering/NumberTest.php b/tests/src/Rendering/NumberTest.php index 27624295..a70d5329 100644 --- a/tests/src/Rendering/NumberTest.php +++ b/tests/src/Rendering/NumberTest.php @@ -19,7 +19,7 @@ class NumberTest extends TestCase { use TestSuiteTestCaseTrait; - public function setUp() + public function setUp(): void { parent::setUp(); $context = new Context(); diff --git a/tests/src/Rendering/TextTest.php b/tests/src/Rendering/TextTest.php index 237def90..c52ff133 100644 --- a/tests/src/Rendering/TextTest.php +++ b/tests/src/Rendering/TextTest.php @@ -39,7 +39,7 @@ class TextTest extends TestCase */ private $citeproc; - public function setUp() + public function setUp(): void { } diff --git a/tests/src/Style/MacroTest.php b/tests/src/Style/MacroTest.php index 6ccfb636..410f2f23 100644 --- a/tests/src/Style/MacroTest.php +++ b/tests/src/Style/MacroTest.php @@ -15,7 +15,7 @@ class MacroTest extends TestCase { - public function setUp() + public function setUp(): void { parent::setUp(); } diff --git a/tests/src/Util/PageHelperTest.php b/tests/src/Util/PageHelperTest.php index 2837e712..92483a87 100644 --- a/tests/src/Util/PageHelperTest.php +++ b/tests/src/Util/PageHelperTest.php @@ -22,7 +22,7 @@ class PageHelperTest extends TestCase private $minimalTwo; private $expanded; - public function setUp() + public function setUp(): void { parent::setUp(); $this->chicago = new PageRangeFormats(PageRangeFormats::CHICAGO); From 443965a77334eb99545915ad823e22ff5167dd6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ttger?= Date: Sun, 8 May 2022 11:52:24 +0200 Subject: [PATCH 3/6] changed supported PHP versions in README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 15e771c8..89536dec 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,9 @@ [![Code Coverage](https://scrutinizer-ci.com/g/seboettg/citeproc-php/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/seboettg/citeproc-php/code-structure/master/code-coverage/src/) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/seboettg/citeproc-php/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/seboettg/citeproc-php/?branch=master) [![Code Intelligence Status](https://scrutinizer-ci.com/g/seboettg/citeproc-php/badges/code-intelligence.svg?b=master)](https://scrutinizer-ci.com/code-intelligence) -![PHP](https://img.shields.io/badge/PHP-7.1-green.svg?style=flat) -![PHP](https://img.shields.io/badge/PHP-7.2-green.svg?style=flat) ![PHP](https://img.shields.io/badge/PHP-7.3-green.svg?style=flat) ![PHP](https://img.shields.io/badge/PHP-7.4-green.svg?style=flat) +![PHP](https://img.shields.io/badge/PHP-8.0-green.svg?style=flat) citeproc-php is a full-featured CSL 1.0.1 processor that renders bibliographic metadata into html formatted citations or bibliographies using CSL stylesheets. citeproc-php renders bibliographies as well as citations (except of [Citation-specific Options](http://docs.citationstyles.org/en/stable/specification.html#citation-specific-options)). From 2312ed73b92b4ebf3a936fe7188afec14158d512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ttger?= Date: Sun, 8 May 2022 12:13:23 +0200 Subject: [PATCH 4/6] Test case for #106 --- .../humans/bugfix-github-106.txt | 347 ++++++++++++++++++ tests/src/BugfixTest.php | 5 + 2 files changed, 352 insertions(+) create mode 100644 tests/fixtures/basic-tests/processor-tests/humans/bugfix-github-106.txt diff --git a/tests/fixtures/basic-tests/processor-tests/humans/bugfix-github-106.txt b/tests/fixtures/basic-tests/processor-tests/humans/bugfix-github-106.txt new file mode 100644 index 00000000..24ebddf4 --- /dev/null +++ b/tests/fixtures/basic-tests/processor-tests/humans/bugfix-github-106.txt @@ -0,0 +1,347 @@ +>>===== MODE =====>> +bibliography +<<===== MODE =====<< + +>>===== RESULT =====>> +
+
“Article Title, With a Comma”. My Publisher.
+
+<<===== RESULT =====<< + +>>===== CSL =====>> + + +<<===== CSL =====<< + +>>===== INPUT =====>> +[ + { + "container-title": "My publisher", + "id": "ITEM-1", + "title": "Article title, with a comma.", + "type": "webpage" + } +] +<<===== INPUT =====<< diff --git a/tests/src/BugfixTest.php b/tests/src/BugfixTest.php index 2c866305..4d069179 100644 --- a/tests/src/BugfixTest.php +++ b/tests/src/BugfixTest.php @@ -140,4 +140,9 @@ public function testBugfixGithub95() { $this->runTestSuite('bugfix-github-95'); } + + public function testBugfixGithub106() + { + $this->runTestSuite('bugfix-github-106'); + } } From faebe346d49aa2c5a067d534d635c1d713020243 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ttger?= Date: Sun, 8 May 2022 12:20:43 +0200 Subject: [PATCH 5/6] gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index d11ba5a3..65aedb26 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ composer.lock build/ review/ +.phpunit.result.cache From 1520b9b815c9c2840b6009b7136f30580eb55bb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ttger?= Date: Sun, 8 May 2022 12:34:18 +0200 Subject: [PATCH 6/6] fixed regex to find punctuations in texts --- src/Styles/QuotesTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Styles/QuotesTrait.php b/src/Styles/QuotesTrait.php index 7b2954ca..30b8346a 100644 --- a/src/Styles/QuotesTrait.php +++ b/src/Styles/QuotesTrait.php @@ -50,7 +50,7 @@ public function addSurroundingQuotes($text) $punctuationInQuotes = CiteProc::getContext()->getLocale()->filter("options", "punctuation-in-quote"); $text = $this->replaceOuterQuotes($text, $openQuote, $closeQuote); if (null !== $punctuationInQuotes || $punctuationInQuotes === false) { - if (preg_match("/([^\.,;]+)([\.,;]{1,})$/", $text, $match)) { + if (preg_match("/^(.+)([\.,;]+)$/", $text, $match)) { $punctuation = substr($match[2], -1); if ($this->suffix !== $punctuation) { $text = $match[1] . substr($match[2], 0, strlen($match[2]) - 1);