ruby / ruby/csv

CSV parser fails with mixed quoting and non-standard row_sep

Open
#107 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
218
Forks
135
Avg merge
15h 40m
Merged PRs (30d)
1

Description

opts = {row_sep: "|\n", col_sep: ","}
CSV.parse(CSV.generate(opts) { |csv|
  csv << ["yes, it's true"];
  csv << [ "CSV is broken"];
  csv << ["uhoh!"]; }, opts)

In the example above, the parser will raise a CSV::MalformedCSVError (Unquoted fields do not allow new line <"\n"> in line 2.) error.

It will succeed if any of the following are done:

  1. pass force_quotes: true to generate
  2. add a comma in each row
  3. remove the comma from the first row
  4. use row_sep: "\n"

Therefore, the problem seems to be that a non-standard row_sep + lines with a field being quoted in one row and unquoted in the next.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the example with CSV.generate and CSV.parse using row_sep: "|\n", then compare the quoted and unquoted rows against the cases that succeed. Trace how the parser handles row separators and field quoting; done means the mixed-quoting input parses without CSV::MalformedCSVError while the existing alternatives remain valid.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.