Forums | Admin

Discussion Forums: open-discussion

Start New Thread Start New Thread

 

By: Stefan Natchev
RE: Should FasterCSV parse malformed CSVs ? [ reply ]  
2007-11-26 20:34
Of course! Thank you, this is a lot more elegant than the patches to #parse_headers that I was attempting.

By: James Gray
RE: Should FasterCSV parse malformed CSVs ? [ reply ]  
2007-11-26 20:13
My opinion is that this issue is better addresses on an application specific basis using a custom converter:

#!/usr/bin/env ruby -wKU

require "rubygems"
require "faster_csv"

EXAMPLE = <<END_CSV
one,two,
1,2,3
END_CSV

p FCSV.parse( EXAMPLE,
:headers => true,
:header_converters => lambda { |h| h ? h.to_sym : :unknown } )

__END__

I'm willing to hear other opinions though.

James Edward Gray II

By: Stefan Natchev
Should FasterCSV parse malformed CSVs ? [ reply ]  
2007-11-26 19:24
I have a case where users submit csvs that sometimes have trailing commas in the header row of a csv file. This causes FasterCSV to break when trying to convert the header because of a nil element.

So my question is: should FasterCSV attempt to parse these (slightly) malformed csv documents? If not, should there be any kind of ParseExceptions being raised?