spring-batch
spring-batch copied to clipboard
JsonRecordSeparatorPolicy doesn't handle braces inside quoted strings properly [BATCH-2125]
Frans Flippo opened BATCH-2125 and commented
isEndOfRecord is currently implemented as:
public boolean isEndOfRecord(String line) {
return StringUtils.countOccurrencesOf(line, "{") == StringUtils.countOccurrencesOf(line, "}")
&& line.trim().endsWith("}");
}
This is too simple. Nested braces inside quoted strings will be considered by the above code to unbalance the number of opening and closing braces.
Only braces outside of quotation marks should be considered. I think iterating over the string character by character, keeping track of whether or not we're inside quotation marks, is the only way to handle this.
I can write an implementation if desired.
Affects: 2.1.0
Attachments:
- BATCH-2125.jar (34.87 kB)
Frans Flippo commented
Added JAR file with JsonRecordSeparatorPolicyTest.java that reproduces this. (Run as java -jar BATCH-2125.jar).