Skip to content

Commit dbe090e

Browse files
feystMark van der Feijst
authored and
Mark van der Feijst
committed
Improve UNB Interchange Header recognition for syntax identifier
1 parent 9f2c96e commit dbe090e

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/EDI/Parser.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -505,18 +505,18 @@ private function unwrap(string &$string): array
505505
);
506506
}
507507

508+
$unbRegex = sprintf(
509+
'/^(UNA[^%1$s]+%1$s\W?\W?)?UNB%2$s(?<syntax_identifier>\w{4})%3$s/m',
510+
$this->symbEnd,
511+
$this->sepData,
512+
$this->sepComp,
513+
);
508514
if (
509515
! $this->unbChecked
510-
&&
511-
\strpos($string, 'UNB') === 0
516+
&& false !== preg_match($unbRegex, $string, $unbMatches)
517+
&& isset($unbMatches['syntax_identifier'])
512518
) {
513-
$this->analyseUNB(
514-
(string) \preg_replace(
515-
"#^UNB\+#",
516-
'',
517-
\substr($string, 0, 8)
518-
)
519-
);
519+
$this->analyseUNB($unbMatches['syntax_identifier']);
520520
}
521521
if (preg_match_all("/[A-Z0-9]+(?:\?'|$)[\r\n]+/i", $string, $matches, PREG_OFFSET_CAPTURE) > 0) {
522522
$this->errors[] = 'This file contains some segments without terminators';

tests/files/example_utf8.edi

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
UNA:+.? '
12
UNB+UNOC:1+1556150:31B+8888888:ZZ+160727:0953+1'
23
UNH+142+DESADV:0:96A:UN'
34
BGM+351+Y02197250+700101'

0 commit comments

Comments
 (0)