spring-batch icon indicating copy to clipboard operation
spring-batch copied to clipboard

JsonRecordSeparatorPolicy doesn't handle braces inside quoted strings properly [BATCH-2125]

Open spring-projects-issues opened this issue 12 years ago • 1 comments

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:

spring-projects-issues avatar Oct 16 '13 08:10 spring-projects-issues

Frans Flippo commented

Added JAR file with JsonRecordSeparatorPolicyTest.java that reproduces this. (Run as java -jar BATCH-2125.jar).

spring-projects-issues avatar Oct 17 '13 05:10 spring-projects-issues