Menu

#38 Parsing escaped quotes as double quotes

v1.0 (example)
closed
None
5
2015-08-25
2015-08-06
Steiny
No

I asked a similar question a week ago but I had it the wrong way around. What I want is to escape quotes with two quotes.

For example: "with,comma","with""quote","with\backslash"

I tried in 2.2 and it does not parse this as expected. In 3.4 this throws an UnsupportedOperationException. So it seems there was a concious decision to prevent this. Why is this? It seem perfectly valid CSV to me.

The interesting thing here is that the CSVWriter can write this out perfectly fine. The problem comes from the CSVParser.parseLineMulti(String) where it always checks the escape character first.

This may be similar to the other question that was raised recently but the quote and escape characters were unassigned rather than double quote.

Discussion

  • Scott Conway

    Scott Conway - 2015-08-08

    Hello Steiny - please send me your code. The default builder works for me - the test I wrote below passes.

    @Test
    public void suportRequest38DoubleQuotesIssue() throws IOException {

        StringBuilder sb = new StringBuilder(CSVParser.INITIAL_READ_SIZE);
    
        sb.append("\"with,comma\",\"with\"\"quote\",\"with\\\\backslash\"");
    
        StringReader stringReader = new StringReader(sb.toString());
    
        CSVReaderBuilder builder = new CSVReaderBuilder(stringReader);
        CSVReader csvReader = builder.build();
    
        String item[] = csvReader.readNext();
    
        assertEquals(3, item.length);
        assertEquals("with,comma", item[0]);
        assertEquals("with\"quote", item[1]);
        assertEquals("with\\backslash", item[2]);
    }
    
     
  • Scott Conway

    Scott Conway - 2015-08-08
    • status: open --> pending
    • assigned_to: Scott Conway
     
  • Scott Conway

    Scott Conway - 2015-08-25
    • status: pending --> closed
     

Log in to post a comment.

MongoDB Logo MongoDB