Menu

#261 Quote read as part of the value when using keepCarriageReturn

v1.0 (example)
open
None
5
3 days ago
2025-07-21
Mika ds
No

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

Discussion

  • Scott Conway

    Scott Conway - 2025-07-21

    Hello Mika - I will attempt to create a JUnit test that replicates this issue this weekend and work on it as time permits.

     
  • Scott Conway

    Scott Conway - 2025-07-21
    • assigned_to: Scott Conway
     
  • Scott Conway

    Scott Conway - 3 days ago

    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

    String csv = """
    "ab"\r
    "x"
    """;
    

    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.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.