Certain Segment Separators Are Ignored
Closed this issue · 4 comments
GoogleCodeExporter commented
What steps will reproduce the problem?
1. Create an EDI file with separators that correspond to Java regex special
characters (for example, one with lines ending in '^').
2. Run a test that parses the segments using a Cf specification.
3. Look for, and print out some segments.
What is the expected output? What do you see instead?
The segments such as (ISA, GS, ST) should be discovered and printed out.
Segments other than ISA are not found, and the ISA segment is (incorrectly) the
whole document.
What version of the product are you using? On what operating system?
v0.9, on osx with jdk 1.6.0_29
Please provide any additional information below.
Here is a fix...
In X12Parser.java, change this...
private X12 scanSource(Scanner scanner, Context context) {
scanner.useDelimiter(context.getSegmentSeparator() + "\r\n|"
+ context.getSegmentSeparator() + "\n|"
+ context.getSegmentSeparator());
...to something like this...
private X12 scanSource(Scanner scanner, Context context) {
Character segmentSeparator = context.getSegmentSeparator();
String quotedSeparator = Pattern.quote(segmentSeparator.toString());
scanner.useDelimiter(quotedSeparator + "\r\n|"
+ quotedSeparator + "\n|"
+ quotedSeparator);
Original issue reported on code.google.com by damien.b...@gmail.com
on 19 Dec 2011 at 5:56
GoogleCodeExporter commented
I can avoid this bug if I replace the regexp control character (as segment
separator) before I parse it.
<pre>
String disallowed = "|^$.()\\?+*{}[]";
char segmentSeparator = x12Content.charAt(X12Parser.POS_SEGMENT);
if (disallowed.indexOf(segmentSeparator)>=0) {
String allowed = "~&@#%ߣĐ";
for (int i=0; i<allowed.length(); i++) {
char c = allowed.charAt(i);
if (x12Content.indexOf(c)<0) {
x12Content = x12Content.replace(segmentSeparator, c);
break;
}
}
}
</pre>
Original comment by kokog.pr...@gmail.com
on 7 Nov 2012 at 3:29
GoogleCodeExporter commented
[deleted comment]
GoogleCodeExporter commented
Code fix has been added to the trunk. New version will be released soon. Till
then build from the source. Thanks for your suggestions.
Original comment by p2b...@gmail.com
on 19 Apr 2013 at 9:09
GoogleCodeExporter commented
Original comment by p2b...@gmail.com
on 21 May 2013 at 6:08
- Changed state: Fixed