Skip to content

Commit 6fc2fe5

Browse files
committedJul 29, 2018
Merge branch 'tophsic-fix-release-character'
2 parents d241211 + c8f8ba8 commit 6fc2fe5

8 files changed

+85
-11
lines changed
 

‎phpunit.xml

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
</whitelist>
1313
</filter>
1414
<logging>
15-
<log type="coverage-html" target="./codeCoverage" charset="UTF-8"
16-
yui="true" highlight="true"/>
15+
<log type="coverage-html" target="./codeCoverage"/>
1716
</logging>
18-
</phpunit>
17+
</phpunit>

‎src/EDI/Parser.php

+21-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class Parser
3131
* @var string : release character (default ?)
3232
*/
3333
private $symbRel;
34+
private $symbUnescapedRel;
3435
/**
3536
* @var string : repetition character (no use but here) (default *)
3637
*/
@@ -39,6 +40,10 @@ class Parser
3940
* @var string : end character (default ')
4041
*/
4142
private $symbEnd;
43+
/**
44+
* @var string : safe string (default §SS§)
45+
*/
46+
private $stringSafe;
4247
/**
4348
* @var string : encoding (default UNOB)
4449
*/
@@ -175,8 +180,10 @@ private function resetUNA()
175180
$this->sepData = "\+";
176181
$this->sepDec = "."; // See later if a preg_quote is needed
177182
$this->symbRel = "\?";
183+
$this->symbUnescapedRel = "?";
178184
$this->symbRep = "*"; // See later if a preg_quote is needed
179185
$this->symbEnd = "'";
186+
$this->stringSafe = "§SS§";
180187
$this->unaChecked = false;
181188
}
182189

@@ -209,6 +216,7 @@ public function analyseUNA($line)
209216
$this->sepDec = $line{2}; // See later if a preg_quote is needed
210217
if (isset($line{3})) {
211218
$this->symbRel = preg_quote($line{3}, self::$DELIMITER);
219+
$this->symbUnescapedRel = $line{3};
212220
if (isset($line{4})) {
213221
$this->symbRep = $line{4}; // See later if a preg_quote is needed
214222
if (isset($line{5})) {
@@ -281,7 +289,9 @@ private function unwrap($string)
281289
$this->analyseUNB(preg_replace("#^UNB\+#", "", substr($string, 0, 8)));
282290
}
283291

284-
$file=preg_split(self::$DELIMITER."(?<!".$this->symbRel.")".$this->symbEnd.self::$DELIMITER."i", $string);
292+
$regex="/(([^".$this->symbRel."]".$this->symbRel."{2})+|[^".$this->symbRel."])".$this->symbEnd."/";
293+
$string=preg_replace($regex, "$1".$this->stringSafe, $string);
294+
$file=preg_split(self::$DELIMITER.$this->stringSafe.self::$DELIMITER."i", $string);
285295
$end = stripslashes($this->symbEnd);
286296
foreach ($file as $fc => &$line) {
287297
if (trim($line) == '') {
@@ -297,6 +307,7 @@ private function splitSegment($str)
297307
{
298308
$str = strrev(preg_replace(self::$DELIMITER.$this->symbEnd.self::$DELIMITER, "", strrev($str), 1));//remove ending symbEnd
299309
$str = trim($str);
310+
$str=preg_replace(self::$DELIMITER.$this->symbRel."{2}".self::$DELIMITER, $this->stringSafe, $str);
300311
$matches=preg_split(self::$DELIMITER."(?<!".$this->symbRel.")".$this->sepData.self::$DELIMITER, $str); //split on sepData if not escaped (negative lookbehind)
301312
foreach ($matches as &$value) {
302313
if (preg_match(self::$DELIMITER."(?<!".$this->symbRel.")".$this->symbEnd.self::$DELIMITER, $value)) {
@@ -313,12 +324,19 @@ private function splitSegment($str)
313324
//Composite data element
314325
private function splitData($str)
315326
{
327+
$replace = function($string) {
328+
$regex=self::$DELIMITER.$this->symbRel."(?=".$this->symbRel.")|".$this->symbRel."(?=".$this->sepData.")|".$this->symbRel."(?=".$this->sepComp.")|".$this->symbRel."(?=".$this->symbEnd.")".self::$DELIMITER;
329+
$string=preg_replace($regex, "", $string);
330+
return preg_replace(self::$DELIMITER.$this->stringSafe.self::$DELIMITER, $this->symbUnescapedRel, $string);
331+
};
332+
316333
$arr=preg_split(self::$DELIMITER."(?<!".$this->symbRel.")".$this->sepComp.self::$DELIMITER, $str); //split on sepComp if not escaped (negative lookbehind)
334+
317335
if (count($arr)==1) {
318-
return preg_replace(self::$DELIMITER.$this->symbRel."(?=".$this->symbRel.")|".$this->symbRel."(?=".$this->sepData.")|".$this->symbRel."(?=".$this->sepComp.")|".$this->symbRel."(?=".$this->symbEnd.")".self::$DELIMITER, "", $str); //remove symbRel if not escaped
336+
return $replace($str);
319337
}
320338
foreach ($arr as &$value) {
321-
$value=preg_replace(self::$DELIMITER.$this->symbRel."(?=".$this->symbRel.")|".$this->symbRel."(?=".$this->sepData.")|".$this->symbRel."(?=".$this->sepComp.")|".$this->symbRel."(?=".$this->symbEnd.")".self::$DELIMITER, "", $value);
339+
$value=$replace($value);
322340
}
323341
return $arr;
324342
}

‎tests/EDITest/AnalyserTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* @package EDITest
1212
* @author Marius Teller <marius.teller@modotex.com>
1313
*/
14-
class AnalyserTest extends \PHPUnit_Framework_TestCase
14+
class AnalyserTest extends \PHPUnit\Framework\TestCase
1515
{
1616
/**
1717
* @var Analyser

‎tests/EDITest/EncoderTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @package EDITest
1010
* @author Stefano Sabatini <sabas88@gmail.com>
1111
*/
12-
class EncoderTest extends \PHPUnit_Framework_TestCase
12+
class EncoderTest extends \PHPUnit\Framework\TestCase
1313
{
1414
public function testEncodeNull()
1515
{

‎tests/EDITest/InterpreterTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @package EDITest
1414
* @author Mark Davidson <mark@4each.co.uk>
1515
*/
16-
class InterpreterTest extends \PHPUnit_Framework_TestCase
16+
class InterpreterTest extends \PHPUnit\Framework\TestCase
1717
{
1818

1919
public function testCOARRI()

‎tests/EDITest/ParserTest.php

+32-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* @author Stefano Sabatini <sabas88@gmail.com>
1111
*/
1212

13-
class ParserTest extends \PHPUnit_Framework_TestCase
13+
class ParserTest extends \PHPUnit\Framework\TestCase
1414
{
1515
public function testCustomStripRegex()
1616
{
@@ -166,4 +166,35 @@ public function testUNAString()
166166
$result=$p->errors();
167167
$this->assertEmpty($result);
168168
}
169+
170+
public function testReleaseCharacter()
171+
{
172+
$p=new Parser();
173+
$loaded=$p->load(__DIR__."/../files/example_release_character.edi");
174+
$result=$p->errors();
175+
$this->assertEmpty($result);
176+
177+
$this->assertEquals($loaded[5][2], 'NO MORE FLIGHTS 1');
178+
$this->assertEquals($loaded[6][2], 'NO MORE FLIGHTS 2?');
179+
$this->assertEquals($loaded[7][2], 'NO MORE \' FLIGHTS 3');
180+
$this->assertEquals($loaded[8][2], 'NO MORE ? FLIGHTS 3');
181+
$this->assertEquals($loaded[9][2], 'NO MORE ?\' FLIGHTS 3');
182+
183+
$this->assertEquals($loaded[10][2], 'FIELD 1');
184+
$this->assertEquals($loaded[10][3], 'FIELD 2');
185+
186+
$this->assertEquals($loaded[11][2], 'FIELD 1?');
187+
$this->assertEquals($loaded[11][3], 'FIELD 2');
188+
189+
$this->assertEquals($loaded[12][2], 'FIELD 1?+FIELD 2');
190+
191+
$this->assertEquals($loaded[13][2][0], 'FIELD 1.1');
192+
$this->assertEquals($loaded[13][2][1], 'FIELD 1.2');
193+
194+
$this->assertEquals($loaded[14][2][0], 'FIELD 1.1?');
195+
$this->assertEquals($loaded[14][2][1], 'FIELD 1.2');
196+
197+
$this->assertEquals($loaded[15][2], 'FIELD 1.1?:FIELD 1.2');
198+
}
199+
169200
}

‎tests/EDITest/ReaderTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @package EDITest
1010
* @author Uldis Nelsons <uldis@weberp.lv>
1111
*/
12-
class ReaderTest extends \PHPUnit_Framework_TestCase
12+
class ReaderTest extends \PHPUnit\Framework\TestCase
1313
{
1414
public function testReadEdiDataValue()
1515
{
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
UNA:+.? '
2+
UNB+IATB:1+6XPPC+LHPPC+940101:0950+1'
3+
UNH+1+PAORES:93:1:IA'
4+
MSG+1:45'
5+
IFT+3+XYZCOMPANY AVAILABILITY'
6+
ERC+A7V:1:AMD'
7+
IFT+3+NO MORE FLIGHTS 1'
8+
IFT+3+NO MORE FLIGHTS 2??'
9+
IFT+3+NO MORE ?' FLIGHTS 3'
10+
IFT+3+NO MORE ?? FLIGHTS 3'
11+
IFT+3+NO MORE ???' FLIGHTS 3'
12+
IFT+3+FIELD 1+FIELD 2'
13+
IFT+3+FIELD 1??+FIELD 2'
14+
IFT+3+FIELD 1???+FIELD 2'
15+
IFT+3+FIELD 1.1:FIELD 1.2'
16+
IFT+3+FIELD 1.1??:FIELD 1.2'
17+
IFT+3+FIELD 1.1???:FIELD 1.2'
18+
ODI'
19+
TVL+240493:1000::1220+FRA+JFK+DL+400+C'
20+
PDI++C:3+Y::3+F::1'
21+
APD+74C:0:::6++++++6X'
22+
TVL+240493:1740::2030+JFK+MIA+DL+081+C'
23+
PDI++C:4'
24+
APD+EM2:0:1630::6+++++++DA'
25+
UNT+14+1'
26+
UNZ+1+1'

0 commit comments

Comments
 (0)
Please sign in to comment.