From 7233357075aa2eed6431b29104afaf6a3b8b19dd Mon Sep 17 00:00:00 2001 From: GaziYucel Date: Wed, 22 May 2024 15:07:13 +0200 Subject: [PATCH] pkp/pkp-lib#9946 Do not remove numbers from the beginning of each citation: * https://github.com/pkp/pkp-lib/issues/9946 * https://forum.pkp.sfu.ca/t/if-a-reference-list-item-starts-with-a-numeral-it-is-removed-3-1-2-4-and-3-3-0-15 --- classes/citation/CitationListTokenizerFilter.inc.php | 7 ++----- .../classes/citation/CitationListTokenizerFilterTest.php | 8 ++++---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/classes/citation/CitationListTokenizerFilter.inc.php b/classes/citation/CitationListTokenizerFilter.inc.php index c893f668d98..6e0ae4384f5 100644 --- a/classes/citation/CitationListTokenizerFilter.inc.php +++ b/classes/citation/CitationListTokenizerFilter.inc.php @@ -47,11 +47,8 @@ function &process(&$input) { } else { $citations = explode("\n", $input); } - // 4) Remove numbers from the beginning of each citation. - foreach($citations as $index => $citation) { - $citations[$index] = PKPString::regexp_replace('/^\s*[\[#]?[0-9]+[.)\]]?\s*/', '', $citation); - } - + // 4) Remove whitespace from the beginning and the end of each citation. + $citations = array_map('trim', $citations); return $citations; } } diff --git a/tests/classes/citation/CitationListTokenizerFilterTest.php b/tests/classes/citation/CitationListTokenizerFilterTest.php index 7d0ba539ae5..aec1cc7110c 100644 --- a/tests/classes/citation/CitationListTokenizerFilterTest.php +++ b/tests/classes/citation/CitationListTokenizerFilterTest.php @@ -25,10 +25,10 @@ public function testCitationListTokenizerFilter() { $tokenizer = new CitationListTokenizerFilter(); $rawCitationList = "\t1. citation1\n\n2 citation2\r\n 3) citation3\n[4]citation4"; $expectedResult = array( - 'citation1', - 'citation2', - 'citation3', - 'citation4' + '1. citation1', + '2 citation2', + '3) citation3', + '[4]citation4' ); self::assertEquals($expectedResult, $tokenizer->process($rawCitationList));