Skip to content

Latest commit

 

History

History
25 lines (19 loc) · 764 Bytes

parsing-a-csv-with-quotes-in-the-data.md

File metadata and controls

25 lines (19 loc) · 764 Bytes

Parsing A CSV With Quotes In The Data

If a CSV contains unescaped quote characters--like you might find in a CSV full of measurement data--then Ruby's CSV library will be unable to parse it.

Here is what happens with a line of CSV about some lumber:

> require 'csv'
> CSV.parse_line('oak,2",4"')
CSV::MalformedCSVError (Illegal quoting in line 1.)

However, we can enable some more lenient, liberal parsing of the data with the liberal_parsing argument.

> require 'csv'
> CSV.parse_line('oak,2",4"', liberal_parsing: true)
=> ["oak", "2\"", "4\""]

source