From 0832384f99e1aee0a929ab1ccf358e168f016abd Mon Sep 17 00:00:00 2001 From: Tomek Date: Sun, 5 Jan 2025 12:46:25 +0100 Subject: [PATCH 1/2] Updated and added unit tests for improperly parsed question marks --- tests/EDITest/ParserTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/EDITest/ParserTest.php b/tests/EDITest/ParserTest.php index a1e2250..6bb0731 100644 --- a/tests/EDITest/ParserTest.php +++ b/tests/EDITest/ParserTest.php @@ -90,8 +90,10 @@ public static function multipleEscapedSegmentsProvider(): array ["EQD+CX??????DU12?+3456+2?:0'", [['EQD', 'CX???DU12+3456', '2:0']]], ["EQD+CX????????DU12?+3456+2?:0'", [['EQD', 'CX????DU12+3456', '2:0']]], ["EQD+CX??DU12?+3456+2?:0??'", [['EQD', 'CX?DU12+3456', '2:0?']]], - ["EQD+CX??DU12?+3456+2?:0????'", [['EQD', 'CX?DU12+3456', "2:0??'"]]], // TODO? -> ' is correct here? - ["EQD+CX??DU12?+3456+2?:0??????'", [['EQD', 'CX?DU12+3456', "2:0???'"]]], // TODO? -> ' is correct here? + ["EQD+CX??DU12?+3456+2?:0???'", [['EQD', 'CX?DU12+3456', "2:0?'"]]], + ["EQD+CX??DU12?+3456+2?:0????'", [['EQD', 'CX?DU12+3456', "2:0??"]]], + ["EQD+CX??DU12?+3456+2?:0??????'", [['EQD', 'CX?DU12+3456', "2:0???"]]], + ["EQD+CX??DU12?+3456+2?:0???????'", [['EQD', 'CX?DU12+3456', "2:0???'"]]], ["??EQD+CX??DU12?+3456+2?:0'", [['?EQD', 'CX?DU12+3456', '2:0']]], ["????EQD+CX??DU12?+3456+2?:0'", [['??EQD', 'CX?DU12+3456', '2:0']]], ["??????EQD+CX??DU12?+3456+2?:0'", [['???EQD', 'CX?DU12+3456', '2:0']]], From 55eb38a008c2f98653fb3aedbc8c078968cf746b Mon Sep 17 00:00:00 2001 From: Tomek Date: Sun, 5 Jan 2025 12:46:45 +0100 Subject: [PATCH 2/2] Updated terminatorRegex in the parser --- src/EDI/Parser.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EDI/Parser.php b/src/EDI/Parser.php index e1bec00..9166f7a 100644 --- a/src/EDI/Parser.php +++ b/src/EDI/Parser.php @@ -522,10 +522,10 @@ private function unwrap(string &$string): array $this->errors[] = 'This file contains some segments without terminators'; } - $terminatorRegex = '/(([^'.$this->symbRel.']'.$this->symbRel.'{2})+|[^'.$this->symbRel.'])'.$this->symbEnd.'|[\r\n]+/'; + $terminatorRegex = '/((?symbRel.')(?:'.$this->symbRel.$this->symbRel.')*)'.$this->symbEnd.'|[\r\n]+/'; if ($this->strict) { - $terminatorRegex = '/(([^'.$this->symbRel.']'.$this->symbRel.'{2})+|[^'.$this->symbRel.'])'.$this->symbEnd.'/'; + $terminatorRegex = '/((?symbRel.')(?:'.$this->symbRel.$this->symbRel.')*)'.$this->symbEnd.'/'; } $string = (string) \preg_replace(