Quote read as part of the value when using keepCarriageReturn
Brought to you by:
aruckerjones,
sconway
Hello,
I have noticed a bug where the last double quote of a value is read as part of the value. I found two occurences of this bug.
It happens only when all those criteria are met :
- keepCarriageReturn is true,
- the csv contains more than one line,
- windows newlines are used.
The column count seems to not be relevant, so my examples use a single column csv.
I am using this configuration of the reader, with the 'csv' values below.
CSVReader reader = new CSVReaderBuilder(new StringReader((csv)))
.withKeepCarriageReturn(true)
.build();
reader.readNext();
1
It happens when the value IS NOT multiline and contains more than ONE characters.
String csv = """
"ab"\r
"x"
""";
returns
ab" <-- incorrect
while (I have removed the last 'd' ):
String csv = """
"a"\r
"x"
""";
returns
a <-- correct
2
It happens when the value IS multiline and contains more than TWO characters.
String csv = """
"a\r
bcd"\r
"x"
""";
returns
a
bcd" <-- incorrect
while (I have removed the last 'd' ):
String csv = """
"a\r
bc"\r
"x"
""";
returns
a
bc <-- correct
Hello Mika - I will attempt to create a JUnit test that replicates this issue this weekend and work on it as time permits.
Mika please help me understand the string you are trying to parse. If possible please send me a running JUnit test showing your expectations. My issue is when I looked at the following line
it is not a legal csv line to the CSVParser or the RFC4180Parser.
If you want the quotes as part of the data you need to escape it with double quotes.
Also please re-run you code using the 5.12.0 release that was just released today. I am wondering if the fix for bug#259 will solve this issue.