Opened 16 years ago

Closed 9 years ago

Last modified 9 years ago

#2406 closed defect (wontfix)

CSVReadParseLine doesn't properly handle double-backslash

Reported by: dstahlke Owned by: warmerdam
Priority: normal Milestone:
Component: default Version: 1.5.1
Severity: normal Keywords: CSVReadParseLine CSV quote backslash
Cc:

Description

The following line breaks the CSV parser:

1,2,"abc
"" def"

The problem is that CSVReadParseLine has logic that simply checks to see whether there is a backslash in front of a quote but does not have logic that interprets double-backslashes. The example given is then interpreted as having an odd number (three) of quotes.

As a test case, run ogrinfo on the attached file.

Attachments (1)

bad.csv (43 bytes ) - added by dstahlke 16 years ago.
Running ogrinfo on this file doesn't give two features as expected

Download all attachments as: .zip

Change History (4)

by dstahlke, 16 years ago

Attachment: bad.csv added

Running ogrinfo on this file doesn't give two features as expected

comment:1 by Even Rouault, 16 years ago

Hum, this is a bit a limit case for CSV...

In the documentation of the CSV driver, we advertize that quotes in string should be escaped with double quotes. But in the code, we also seem to have the possibility that quotes are escaped with a blackslash (documentation for CSVFindNextLine()). However escaping quote with blackslash doesn't work very well, even on this "simple" case :

lon,lat,label
1,2,"abc \"def"
3,4,"xyz"

The result is :

OGRFeature(bad):1
  lon (String) = 1
  lat (String) = 2
  label (String) = abc \def

OGRFeature(bad):2
  lon (String) = 3
  lat (String) = 4
  label (String) = xyz

So the quote got lost.

I think we also definitely don't want to escape backslash with backslash...

comment:2 by Jukka Rahkonen, 9 years ago

Resolution: wontfix
Status: newclosed

This is so much a corner case and it has been open for 7 years that I think it has been enough. Reopen with some real world use case if needed.

The result that Even wants comes from this peculiar CSV

lon,lat,label
1,2,"abc """def""
3,4,"xyz"

comment:3 by Jukka Rahkonen, 9 years ago

Seems to be related to #5318 so perhaps closing as duplicate would have been a better fit.

Note: See TracTickets for help on using tickets.