From 824687f17e19c1b4a0da346d5d9c0eebf22d5442 Mon Sep 17 00:00:00 2001 From: Michael Edgar Date: Fri, 25 Sep 2020 07:19:56 -0400 Subject: [PATCH 1/4] Look ahead in schema before going back to peer segments --- .../internal/stream/validation/Validator.java | 65 +- .../stream/StaEDIStreamReaderTest.java | 37 + .../EDIFACT/issue122/BAPLIE-d95b.xml | 2403 +++++++++++++++++ .../EDIFACT/issue122/baplie-test.edi | 21 + 4 files changed, 2504 insertions(+), 22 deletions(-) create mode 100644 src/test/resources/EDIFACT/issue122/BAPLIE-d95b.xml create mode 100644 src/test/resources/EDIFACT/issue122/baplie-test.edi diff --git a/src/main/java/io/xlate/edi/internal/stream/validation/Validator.java b/src/main/java/io/xlate/edi/internal/stream/validation/Validator.java index c7bd6842..594b63db 100644 --- a/src/main/java/io/xlate/edi/internal/stream/validation/Validator.java +++ b/src/main/java/io/xlate/edi/internal/stream/validation/Validator.java @@ -131,6 +131,13 @@ void reset(UsageNode root, UsageNode implRoot) { standard = UsageNode.getFirstChild(root); impl = UsageNode.getFirstChild(implRoot); } + + UsageCursor copy() { + UsageCursor copy = new UsageCursor(); + copy.standard = this.standard; + copy.impl = this.impl; + return copy; + } } static class RevalidationNode { @@ -405,6 +412,7 @@ public void validateSegment(ValidationEventHandler handler, CharSequence tag) { clearElements(); final int startDepth = this.depth; + UsageCursor startLoop = null; cursor.standard = correctSegment; cursor.impl = implNode; @@ -430,13 +438,15 @@ public void validateSegment(ValidationEventHandler handler, CharSequence tag) { // Advance to the next segment in the loop cursor.next(nextImpl); // Impl node may be unchanged } else { - // End of the loop - check if the segment appears earlier in the loop - handled = checkPeerSegments(tag, cursor.standard, startDepth, handler); - - if (!handled) { - // Determine if the segment is in a loop higher in the tree or in the transaction whatsoever - handled = checkParents(cursor, tag, startDepth, handler); + if (startDepth == depth) { + /* + * Remember the position of the last known loop's segment in case + * the segment being validated is an earlier sibling that is out of + * proper sequence. + */ + startLoop = cursor.copy(); } + handled = handleLoopEnd(cursor, startLoop, tag, startDepth, handler); } } } @@ -620,10 +630,35 @@ boolean handleLoop(CharSequence tag, UsageNode current, UsageNode currentImpl, i return true; } - boolean checkPeerSegments(CharSequence tag, UsageNode current, int startDepth, ValidationEventHandler handler) { + boolean handleLoopEnd(UsageCursor cursor, UsageCursor startLoop, CharSequence tag, int startDepth, ValidationEventHandler handler) { + boolean handled; + + if (depth > 1) { + // Determine if the segment is in a loop higher in the tree + cursor.nagivateUp(this.depth); + this.depth--; + handled = false; + } else { + // End of the loop - check if the segment appears earlier in the loop + handled = checkPeerSegments(tag, startLoop.standard, startDepth, startDepth, handler); + + if (handled) { + // Found the segment among the last known segment's peers so reset the depth + this.depth = startDepth; + } else { + // Determine if the segment is in the transaction whatsoever + cursor.reset(this.root, this.implRoot); + handled = checkUnexpectedSegment(tag, cursor.standard, startDepth, handler); + } + } + + return handled; + } + + boolean checkPeerSegments(CharSequence tag, UsageNode current, int depth, int startDepth, ValidationEventHandler handler) { boolean handled = false; - if (this.depth == startDepth && current != correctSegment) { + if (depth == startDepth && current != correctSegment) { /* * End of the loop; try to see if we can find the segment among * the siblings of the last good segment. If the last good @@ -652,20 +687,6 @@ boolean checkPeerSegments(CharSequence tag, UsageNode current, int startDepth, V return handled; } - boolean checkParents(UsageCursor cursor, CharSequence tag, int startDepth, ValidationEventHandler handler) { - boolean handled = false; - - if (this.depth > 1) { - cursor.nagivateUp(this.depth); - this.depth--; - } else { - cursor.reset(this.root, this.implRoot); - handled = checkUnexpectedSegment(tag, cursor.standard, startDepth, handler); - } - - return handled; - } - boolean checkUnexpectedSegment(CharSequence tag, UsageNode current, int startDepth, ValidationEventHandler handler) { boolean handled = false; diff --git a/src/test/java/io/xlate/edi/internal/stream/StaEDIStreamReaderTest.java b/src/test/java/io/xlate/edi/internal/stream/StaEDIStreamReaderTest.java index 3f974067..9f55f1d7 100644 --- a/src/test/java/io/xlate/edi/internal/stream/StaEDIStreamReaderTest.java +++ b/src/test/java/io/xlate/edi/internal/stream/StaEDIStreamReaderTest.java @@ -1757,4 +1757,41 @@ void testValidatorResetElement_Issue106() throws Exception { assertEquals(0, unexpected.size()); } + + /** + * Original issue: https://github.com/xlate/staedi/issues/122 + * + * @throws Exception + */ + @Test + void testValidatorLookAhead_Issue122() throws Exception { + EDIInputFactory factory = EDIInputFactory.newFactory(); + Schema transSchema = SchemaFactory.newFactory().createSchema(getClass().getResourceAsStream("/EDIFACT/issue122/BAPLIE-d95b.xml")); + EDIStreamReader reader = factory.createEDIStreamReader(getClass().getResourceAsStream("/EDIFACT/issue122/baplie-test.edi")); + List unexpected = new ArrayList<>(); + + try { + while (reader.hasNext()) { + switch (reader.next()) { + case START_TRANSACTION: + reader.setTransactionSchema(transSchema); + break; + case SEGMENT_ERROR: + case ELEMENT_OCCURRENCE_ERROR: + case ELEMENT_DATA_ERROR: + unexpected.add(reader.getErrorType()); + break; + default: + break; + } + } + } catch (Exception e) { + unexpected.add(e); + } finally { + reader.close(); + } + + assertEquals(0, unexpected.size()); + } + } diff --git a/src/test/resources/EDIFACT/issue122/BAPLIE-d95b.xml b/src/test/resources/EDIFACT/issue122/BAPLIE-d95b.xml new file mode 100644 index 00000000..da65503b --- /dev/null +++ b/src/test/resources/EDIFACT/issue122/BAPLIE-d95b.xml @@ -0,0 +1,2403 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 34 + 35 + 37 + 59 + 60 + 61 + 62 + 63 + 64 + 65 + 66 + 67 + 68 + 69 + 70 + 71 + 72 + 73 + 74 + 75 + 76 + 77 + 78 + 79 + 80 + 81 + 82 + 83 + 84 + 85 + 86 + 87 + 88 + 89 + 90 + 91 + 92 + 93 + 94 + 95 + 96 + 97 + 98 + 99 + 105 + 110 + 120 + 130 + 140 + 150 + 190 + 201 + 202 + 203 + 204 + 205 + 206 + 207 + 208 + 209 + 210 + 211 + 212 + 215 + 220 + 221 + 222 + 223 + 224 + 225 + 226 + 227 + 228 + 229 + 230 + 231 + 232 + 233 + 240 + 241 + 242 + 245 + 270 + 271 + 310 + 311 + 315 + 320 + 325 + 326 + 327 + 328 + 330 + 335 + 340 + 341 + 343 + 345 + 350 + 351 + 370 + 380 + 381 + 382 + 383 + 384 + 385 + 386 + 387 + 388 + 389 + 390 + 393 + 394 + 395 + 396 + 409 + 412 + 425 + 426 + 427 + 428 + 429 + 430 + 431 + 435 + 447 + 448 + 450 + 451 + 452 + 454 + 455 + 456 + 457 + 458 + 460 + 465 + 466 + 467 + 468 + 469 + 481 + 485 + 490 + 491 + 492 + 493 + 520 + 530 + 550 + 575 + 580 + 610 + 621 + 622 + 623 + 624 + 630 + 631 + 632 + 633 + 635 + 640 + 650 + 655 + 700 + 701 + 702 + 703 + 704 + 705 + 706 + 707 + 708 + 709 + 710 + 711 + 712 + 713 + 714 + 715 + 716 + 720 + 722 + 723 + 724 + 730 + 740 + 741 + 743 + 744 + 745 + 746 + 750 + 760 + 761 + 763 + 764 + 765 + 766 + 770 + 775 + 780 + 781 + 782 + 783 + 784 + 785 + 786 + 787 + 788 + 789 + 790 + 791 + 792 + 793 + 794 + 795 + 796 + 797 + 798 + 799 + 810 + 811 + 812 + 820 + 821 + 822 + 823 + 824 + 825 + 830 + 833 + 840 + 841 + 850 + 851 + 852 + 853 + 855 + 856 + 860 + 861 + 862 + 863 + 864 + 865 + 870 + 890 + 895 + 896 + 901 + 910 + 911 + 913 + 914 + 915 + 916 + 917 + 925 + 926 + 927 + 929 + 930 + 931 + 932 + 933 + 934 + 935 + 936 + 937 + 938 + 940 + 941 + 950 + 951 + 952 + 953 + 954 + 955 + 960 + 961 + 962 + 963 + 964 + 965 + 966 + 990 + 991 + 995 + 996 + 998 + + + + + + 12 + 16 + 23 + 25 + 35 + 36 + 37 + 38 + 39 + 42 + 43 + 44 + 52 + 53 + 54 + 55 + 56 + 57 + 58 + 59 + 100 + 101 + 102 + 103 + 104 + 105 + 106 + 107 + 108 + 109 + 110 + 112 + 113 + 114 + 115 + 116 + 117 + 118 + 119 + 120 + 121 + 122 + 123 + 125 + 126 + 127 + 128 + 129 + 130 + 131 + 132 + 133 + 134 + 135 + 136 + 137 + 139 + 140 + 141 + 142 + 143 + 144 + 145 + 146 + 147 + 148 + 149 + 150 + 151 + 152 + 153 + 154 + 155 + 156 + 157 + 158 + 160 + 161 + 162 + 163 + 164 + 165 + 166 + 167 + 168 + 169 + 170 + 172 + 173 + 174 + 175 + 176 + 177 + 178 + 179 + 180 + 181 + 182 + 183 + 184 + 185 + 186 + 187 + 188 + 189 + 190 + 191 + 192 + ZZZ + + + + + A + C + P + AC + AE + AF + AP + AU + AV + BA + BC + BD + BE + BH + BM + BN + BO + BR + BT + BW + CD + CG + CH + CK + CM + CN + CO + CP + CR + CS + CT + CU + CV + CW + CZ + DA + DB + DI + DL + DM + DQ + DR + EA + EB + ED + EE + EI + EN + EP + EQ + ER + ET + EX + FC + FF + FI + FN + FO + FS + FT + FV + FX + GA + GC + GD + GN + HS + IA + IB + II + IL + IP + IS + IT + IV + JB + JE + LA + LB + LC + LI + LO + LS + MA + MB + MF + MG + MH + MR + MS + NA + OH + OI + ON + OP + OR + PB + PC + PD + PE + PF + PI + PK + PL + PP + PQ + PR + PS + PW + PY + RA + RC + RE + RF + RR + RT + SA + SB + SD + SE + SF + SH + SI + SM + SN + SP + SQ + SS + SW + SZ + TB + TE + TF + TI + TL + TN + TP + UC + UN + UO + VA + VC + VM + VN + VP + VR + VS + VT + VV + WE + WM + WN + WR + WS + WY + AAA + AAB + AAC + AAD + AAE + AAG + AAJ + AAK + AAL + AAM + AAN + AAO + AAP + AAQ + AAS + AAT + AAU + AAV + AAY + AAZ + ABA + ABB + ABC + ABD + ABE + ABG + ABH + ABI + ABJ + ABK + ABL + ABO + ABP + ABQ + ABR + ABS + ABT + ABU + ABW + ABY + ACB + ACC + ACD + ACE + ACF + ACG + ACH + ACI + ACJ + ACK + ACL + ACM + ACN + ACO + ACP + ACQ + ACR + ACS + ACT + ACU + ACW + ACX + ADB + ADC + ADD + ADE + ADF + ADG + ADH + ADI + ADJ + ADK + ADP + ADQ + ADR + ADS + ADT + ADU + ADV + ADW + ADY + ADZ + AEA + AEB + AEC + AED + AEE + AEF + AEG + AEH + AEI + AEJ + AEK + AEL + AEM + AEN + AEO + AEP + AEQ + AER + AES + AET + AEU + AEV + AEW + AEX + AEY + AEZ + AFA + AFB + AFC + AFD + AFE + AFF + AFG + AFI + AFJ + AFK + AFL + AFM + AFN + AFO + AFP + AFQ + AFR + AFS + AFT + AFU + AFV + AFW + AFX + AFY + AFZ + AGA + AGB + AGC + AGD + AGE + AGF + AGG + AGH + AGI + AGJ + AGK + AGL + AGM + AGN + AGO + AGP + AGQ + AGR + AGS + AGT + AGU + AGV + AGW + AGX + AGY + AGZ + AHA + AHB + AHC + AHD + AHE + AHF + AHG + AHH + AHI + AHJ + AHK + AHL + AHM + AHN + AHO + AHP + AHQ + AHR + AHS + AHT + AHU + AHV + AHW + AHX + AHY + AHZ + AIA + AIB + AIC + AID + AIE + AIF + AIG + AIH + AII + AIJ + AIK + AIL + AIM + AIN + AIO + AIP + AIQ + AIR + AIS + AIT + AIU + AIV + AIW + AIX + AIY + ASC + AWB + CAS + CEC + CFE + CFO + CKN + CMR + CNO + COF + CRN + CST + DAN + ERN + FLW + GDN + HWB + ICA + ICE + ICO + INB + INN + INO + LAN + LAR + MRN + MSS + MWB + POR + RCN + REN + SRN + STA + UAR + UCN + VON + ZZZ + + + + + + + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 34 + 35 + 36 + 37 + 38 + 39 + 40 + 41 + 42 + 43 + 44 + 45 + 46 + 47 + 48 + 49 + 50 + 51 + 52 + 53 + + + + + + 2 + 3 + 4 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 20 + 21 + 22 + 35 + 36 + 37 + 38 + 39 + 42 + 44 + 45 + 46 + 47 + 48 + 49 + 50 + 51 + 52 + 53 + 54 + 55 + 58 + 59 + 60 + 61 + 63 + 64 + 65 + 67 + 69 + 71 + 72 + 74 + 75 + 76 + 79 + 81 + 84 + 85 + 89 + 90 + 91 + 92 + 93 + 94 + 95 + 96 + 97 + 101 + 107 + 108 + 109 + 110 + 111 + 113 + 114 + 115 + 117 + 119 + 123 + 124 + 125 + 126 + 128 + 129 + 131 + 132 + 133 + 134 + 135 + 136 + 137 + 138 + 140 + 141 + 143 + 144 + 146 + 147 + 148 + 149 + 150 + 151 + 152 + 153 + 154 + 155 + 156 + 157 + 158 + 159 + 160 + 161 + 162 + 163 + 164 + 165 + 166 + 167 + 168 + 169 + 170 + 171 + 172 + 173 + 174 + 175 + 176 + 177 + 178 + 179 + 180 + 181 + 182 + 183 + 184 + 185 + 186 + 187 + 188 + 189 + 190 + 191 + 192 + 193 + 194 + 195 + 196 + 197 + 198 + 199 + 200 + 201 + 202 + 203 + 204 + 205 + 206 + 207 + 208 + 209 + 210 + 211 + 212 + 213 + 214 + 215 + 216 + 218 + 219 + 221 + 222 + 223 + 224 + 225 + 226 + 227 + 228 + 229 + 230 + 231 + 232 + 233 + 234 + 235 + 236 + 237 + 238 + 239 + 240 + 242 + 243 + 244 + 245 + 246 + 247 + 248 + 249 + 250 + 251 + 252 + 253 + 254 + 255 + 257 + 258 + 259 + 260 + 261 + 262 + 263 + 264 + 265 + 266 + 267 + 268 + 270 + 271 + 272 + 273 + 274 + 275 + 276 + 277 + 278 + 279 + 280 + 281 + 282 + 283 + 284 + 285 + 286 + 287 + 288 + 290 + 291 + 292 + 293 + 294 + 295 + 296 + 297 + 298 + 299 + 300 + 301 + 302 + 303 + 304 + 305 + 306 + 307 + 308 + 309 + 310 + 311 + 312 + 313 + 314 + 315 + 316 + 317 + 318 + 319 + 320 + 321 + 322 + 323 + 324 + 325 + 326 + 327 + 328 + 329 + 330 + 331 + 332 + 333 + 334 + 335 + 336 + 337 + 338 + 339 + 340 + 341 + 342 + 343 + 344 + 345 + 346 + 347 + 348 + 349 + 350 + 351 + 352 + 353 + 354 + ZZZ + + + + + 2 + 3 + 101 + 102 + 103 + 105 + 106 + 107 + 108 + 109 + 110 + 201 + 202 + 203 + 204 + 301 + 302 + 303 + 304 + 305 + 306 + 401 + 402 + 404 + 405 + 501 + 502 + 503 + 600 + 601 + 602 + 603 + 604 + 608 + 609 + 610 + 613 + 614 + 615 + 616 + 701 + 702 + 703 + 704 + 705 + 706 + 707 + 708 + 709 + 710 + 711 + 713 + 715 + 716 + 717 + 718 + 801 + 802 + 803 + 804 + 805 + 806 + 807 + 808 + 809 + 810 + 811 + 812 + 813 + 814 + + + + + + + AA + AB + AE + AF + AG + AH + AI + AK + AL + AM + AN + AO + AP + AQ + AR + AT + AU + AV + AW + AX + AZ + B1 + B2 + BA + BB + BC + BD + BE + BF + BG + BH + BI + BK + BL + BM + BN + BO + BP + BQ + BS + BT + BU + BV + BW + BX + BY + BZ + C1 + C2 + CA + CB + CC + CD + CE + CF + CG + CH + CI + CJ + CK + CL + CM + CN + CO + CP + CQ + CR + CS + CT + CU + CV + CW + CX + CY + CZ + DA + DB + DC + DD + DE + DF + DG + DH + DI + DJ + DK + DL + DM + DN + DO + DP + DQ + DR + DS + DT + DU + DV + DW + DX + DY + DZ + EA + EB + EC + ED + EE + EF + EG + EH + EI + EJ + EK + EL + EM + EN + EO + EP + EQ + ER + ES + ET + EU + EV + EW + EX + EY + EZ + FA + FB + FC + FD + FE + FF + FG + FH + FJ + FK + FL + FM + FN + FO + FP + FR + FT + FW + FX + FY + FZ + GA + GB + GC + GD + GE + GF + GG + GH + GI + GJ + GK + GL + GM + GN + GO + GP + GQ + GR + GS + GT + I1 + I2 + IB + IC + II + IM + IN + IO + IP + IS + IT + IV + LA + LN + LP + MA + MF + MG + MI + MP + MR + MS + MT + N1 + N2 + NI + OA + OB + OF + OI + OO + OP + OR + OS + OT + OV + OY + P1 + P2 + P3 + P4 + PA + PB + PC + PD + PE + PF + PG + PH + PI + PJ + PK + PL + PM + PN + PO + PQ + PR + PS + PT + PW + PX + PY + PZ + RA + RB + RE + RF + RH + RI + RL + RM + RP + RS + RV + RW + SB + SE + SF + SG + SI + SK + SN + SO + SR + SS + ST + SU + SX + SY + SZ + TC + TD + TR + TS + TT + UC + UD + UP + VN + WD + WH + WM + WS + COP + CPD + DCP + TCP + UHP + WPA + ZZZ + + + + + + + + 1 + + + + + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 34 + 35 + 36 + 37 + 38 + 39 + 40 + 41 + 42 + 43 + 44 + 45 + 46 + 47 + 48 + 49 + 50 + 51 + 52 + 53 + 54 + 55 + 56 + 57 + 58 + 59 + 86 + 87 + 88 + 89 + 90 + 91 + 92 + 93 + 94 + 95 + 96 + 97 + 98 + 99 + 100 + 101 + 102 + 103 + 104 + 105 + 106 + 107 + 108 + 109 + 110 + 111 + 112 + 113 + 114 + 115 + 116 + 117 + 118 + 119 + 120 + 121 + 122 + 123 + 124 + 125 + 126 + 128 + 129 + 130 + 131 + 132 + 133 + 134 + 135 + 136 + 137 + 138 + 139 + 140 + 141 + 142 + 143 + 144 + 145 + 146 + 147 + 148 + 149 + 150 + 151 + 152 + 153 + 154 + 155 + 156 + 157 + 158 + 159 + 160 + 161 + 162 + 163 + 164 + 165 + 166 + 167 + 168 + 169 + 170 + 171 + 172 + 173 + 174 + 175 + 176 + 177 + 178 + 179 + 181 + 182 + 183 + 184 + ZZZ + + + + + + + + + + + + + + 1 + 2 + 4 + 5 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 34 + 35 + 36 + 37 + 38 + 39 + 40 + 41 + 42 + 43 + 44 + 45 + 46 + 47 + 48 + 49 + 50 + 51 + 52 + 53 + 54 + 55 + 56 + 57 + 58 + 60 + 61 + 62 + 64 + 66 + 67 + 68 + 69 + 70 + 71 + 72 + 73 + 74 + 75 + 76 + 77 + 78 + 79 + 80 + 81 + 82 + 83 + 84 + 85 + 86 + 87 + 88 + 89 + 90 + 91 + 92 + 93 + 96 + 97 + 98 + 99 + 100 + 101 + 102 + 103 + 104 + 105 + 106 + 107 + 108 + 109 + 110 + 111 + 113 + 114 + 115 + 116 + 118 + 119 + 120 + 121 + 122 + 123 + 124 + 125 + 126 + 127 + 128 + 129 + 130 + 131 + 132 + 133 + 134 + 135 + 136 + 137 + 138 + 139 + 140 + 141 + 142 + 143 + 144 + 145 + 146 + 147 + 148 + 149 + 151 + 152 + 153 + 154 + 155 + 156 + 157 + 158 + 159 + 160 + 161 + ZZZ + + + + + + + + + + + AA + AB + AC + AD + AF + AG + AP + CA + CO + NA + RE + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/EDIFACT/issue122/baplie-test.edi b/src/test/resources/EDIFACT/issue122/baplie-test.edi new file mode 100644 index 00000000..74e957ff --- /dev/null +++ b/src/test/resources/EDIFACT/issue122/baplie-test.edi @@ -0,0 +1,21 @@ +UNB+UNOA:2+SENDER+RECIPIENT+090304:1230+UNIQUEID1234+++++SHIPPINGLINE' +UNH+SENDER123+BAPLIE:D:95B:UN:SMDG20' +BGM++M1+9' +DTM+137:0903031447:201' +TDT+20+VOYAGENO123+++CARRIERID:172:20+++DLHV:103:ZZZ' +LOC+5+EGPSD:139:6' +LOC+61+GRPIR:139:6' +DTM+132' +DTM+133' +LOC+147+0030586::5' +FTX+ZZZ+++HL' +MEA+WT++KGM:10000' +LOC+9+EGPSD:139:6' +LOC+11+ITSPE:139:6' +LOC+83+AFQLT:139:6' +RFF+BM:1' +EQD+CN+TOLU 2566410++1++5' +DGS+IMD+2.3+2198+045:CEL+1+F-CS-U+16++8' +FTX+AAD+++PHOSPHORUS PENTAFLUORIDE:109.0' +UNT+18+SENDER123' +UNZ+1+UNIQUEID1234' \ No newline at end of file From ab16dfd457866ac668c6e5d53807a00d0e2baf24 Mon Sep 17 00:00:00 2001 From: Michael Edgar Date: Fri, 25 Sep 2020 07:20:32 -0400 Subject: [PATCH 2/4] Bump minor version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index da080232..ea1be463 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ io.xlate staedi - 1.11.1-SNAPSHOT + 1.12.0-SNAPSHOT StAEDI : Streaming API for EDI for Java Streaming API for EDI for Java From b59b4e4006d67f5df0d402c9d5989cc084a9929b Mon Sep 17 00:00:00 2001 From: Michael Edgar Date: Fri, 25 Sep 2020 07:22:52 -0400 Subject: [PATCH 3/4] Save loop position the first time, not based on depth --- .../java/io/xlate/edi/internal/stream/validation/Validator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/xlate/edi/internal/stream/validation/Validator.java b/src/main/java/io/xlate/edi/internal/stream/validation/Validator.java index 594b63db..f38b00a7 100644 --- a/src/main/java/io/xlate/edi/internal/stream/validation/Validator.java +++ b/src/main/java/io/xlate/edi/internal/stream/validation/Validator.java @@ -438,7 +438,7 @@ public void validateSegment(ValidationEventHandler handler, CharSequence tag) { // Advance to the next segment in the loop cursor.next(nextImpl); // Impl node may be unchanged } else { - if (startDepth == depth) { + if (startLoop == null) { /* * Remember the position of the last known loop's segment in case * the segment being validated is an earlier sibling that is out of From ed3c2a48c8319b601944fbbf00ded31d09775f17 Mon Sep 17 00:00:00 2001 From: Michael Edgar Date: Fri, 25 Sep 2020 07:26:11 -0400 Subject: [PATCH 4/4] Remove unnecessary depth comparison --- .../io/xlate/edi/internal/stream/validation/Validator.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/xlate/edi/internal/stream/validation/Validator.java b/src/main/java/io/xlate/edi/internal/stream/validation/Validator.java index f38b00a7..1f5d56ee 100644 --- a/src/main/java/io/xlate/edi/internal/stream/validation/Validator.java +++ b/src/main/java/io/xlate/edi/internal/stream/validation/Validator.java @@ -640,7 +640,7 @@ boolean handleLoopEnd(UsageCursor cursor, UsageCursor startLoop, CharSequence ta handled = false; } else { // End of the loop - check if the segment appears earlier in the loop - handled = checkPeerSegments(tag, startLoop.standard, startDepth, startDepth, handler); + handled = checkPeerSegments(tag, startLoop.standard, handler); if (handled) { // Found the segment among the last known segment's peers so reset the depth @@ -655,10 +655,10 @@ boolean handleLoopEnd(UsageCursor cursor, UsageCursor startLoop, CharSequence ta return handled; } - boolean checkPeerSegments(CharSequence tag, UsageNode current, int depth, int startDepth, ValidationEventHandler handler) { + boolean checkPeerSegments(CharSequence tag, UsageNode current, ValidationEventHandler handler) { boolean handled = false; - if (depth == startDepth && current != correctSegment) { + if (current != correctSegment) { /* * End of the loop; try to see if we can find the segment among * the siblings of the last good segment. If the last good