Revert the behavior of DelimitedLineTokenizer to pre-4
DelimitedLineTokenizer was refactored to improve its performance but its behavior was also slightly changed.
When the input is an empty csv string with double quotes, e.g. the java
String line = "\"\""; the tokenizer returns the same String, whereas
before it was returning an empty string.
This is due to the condition checking for quotes to remove not stripping
the double quotes from the empty csv string (because its length is 2 and
the code check for strictly greater than 2).
The previous code is there 973fe44d6c/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizer.java (L202) and checking for
double quotes at the start and end of the string without special
handling for the empty string.
At test is also added to ensure this won't break again.
Resolves BATCH-2657
This commit is contained in:
committed by
Michael Minella
parent
31c7e8f83f
commit
62a580f52d
@@ -222,7 +222,7 @@ public class DelimitedLineTokenizer extends AbstractLineTokenizer
|
||||
|
||||
String value;
|
||||
|
||||
if ((chars.length > 2) && (chars[start] == quoteCharacter) && (chars[start + len - 1] == quoteCharacter)) {
|
||||
if ((chars.length >= 2) && (chars[start] == quoteCharacter) && (chars[start + len - 1] == quoteCharacter)) {
|
||||
value = new String(chars, start + 1, len - 2);
|
||||
if (value.contains(escapedQuoteString)) {
|
||||
value = StringUtils.replace(value, escapedQuoteString, quoteString);
|
||||
|
||||
Reference in New Issue
Block a user