Bugs: Browse | Submit New | Admin

[#8975] CSV parse problem

Date:
2007-03-01 16:12
Priority:
3
Submitted By:
David Welton (davidw)
Assigned To:
Akinori MUSHA (knu)
Category:
DB / File Formats
State:
Open
Platform:
 
Summary:
CSV parse problem

Detailed description
This is with the latest code from CVS:

irb(main):001:0> require './csv.rb'
=> true
irb(main):002:0> CSV.parse_line 'N;1944;Julie London, Larry "Buster" Crabbe;', ';' 
=> []

The problem is pretty clearly the embedded "Buster", but I'm not sure how to go about fixing it, exactly...

Add A Comment: Notepad

Please login


Followup

Message
Date: 2007-03-01 16:37
Sender: David Welton

"the data I'm dealing with"

Not to suggest that my data ought to be the only design
consideration:-) However, it's not malformed, and so I think
that the "be liberal with what you accept" principal
applies.
Date: 2007-03-01 16:32
Sender: David Welton

This following "fixes" the problem, but then the test
suite
reports failures, because it considers having an embedded
quote an error.  Perhaps it should be a configuration
option, because like it or not, the data I'm dealing with
has embedded quotes.  I suppose I could try and strip them
first, but... then we're sort of back to square one, as they
say.

Thankyou, Dave

--- csv.rb      2 Sep 2006 03:06:33 -0000       1.11
+++ csv.rb      1 Mar 2007 16:29:09 -0000
@@ -331,6 +331,7 @@
       quoted = cr = false
       c = nil
       last_idx = idx
+
       while c = src[idx]
         unless quoted
           fschar = (c == fs_str[fs_idx])
@@ -367,8 +368,6 @@
               last_idx += 1
               quoted = false
               state = :ST_QUOTE
-            else
-              raise IllegalFormatError
             end
           elsif state == :ST_QUOTE
             cell << c.chr

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

Field Old Value Date By
assigned_tonone2007-06-12 01:20zenspider
category_idMisc / Other Standard Library2007-05-29 21:39zenspider