halogenandtoast / excelsior

37 stars 2 forks source link

Incorrect csv parsing #1

Open openhood opened 14 years ago

openhood commented 14 years ago

Hello,

I've a problem with both master and formats branch, using both ree-1.8.7-2010.01 or ruby.1.9.1-p378

If I try :

Excelsior::Reader.rows('"quote string 1";"quoted string 2"', ','){|row| puts row.inspect}

I receive:

["quoted string 1", ";", "quoted string 2"]

Instead of:

["quoted string 1;quoted string 2"]

Am I missing something?

halogenandtoast commented 14 years ago

Strings in csv files should be escaped with two " so your should be doing

"quote string 1"";""quoted string 2"

instead. However excelsior will return to you: quote string 1"";""quoted string 2 instead of quote string 1";"quoted string 2 which I still need to fix

openhood commented 14 years ago

Perhaps if the format is incorrect it should return an error instead of silently returning a wrong result, the problem here is I don't know in advance if the CSV is separated by commas or semi-colons, so a possible approach is to parse the first line using each delimiter and choose the one which has the more results (or which doesn't return an error). With FasterCSV it works as expected, with excelsior however the wrong delimiter don't crash and return even more results. Can I help by providing a bigger set of test cases (input / expected outputs)?

halogenandtoast commented 14 years ago

Test cases are always welcome.