Skip to content

CSV.parse can't handle double double-quoted column at Ruby 2.6.0 #66

Closed
@Watson1978

Description

@Watson1978

At first, I don't know whether the following CSV is valid format.

a,""b""

Ruby 2.5's CSV library handles it well.
However, Ruby 2.6's shows different behavior.

Ruby 2.6

$ ruby -v t.rb
ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-darwin18]
Traceback (most recent call last):
	5: from t.rb:7:in `<main>'
	4: from /Users/watson/.rbenv/versions/2.6.0/lib/ruby/2.6.0/csv.rb:683:in `parse'
	3: from /Users/watson/.rbenv/versions/2.6.0/lib/ruby/2.6.0/csv.rb:1180:in `read'
	2: from /Users/watson/.rbenv/versions/2.6.0/lib/ruby/2.6.0/csv.rb:1180:in `to_a'
	1: from /Users/watson/.rbenv/versions/2.6.0/lib/ruby/2.6.0/csv.rb:1171:in `each'
/Users/watson/.rbenv/versions/2.6.0/lib/ruby/2.6.0/csv/parser.rb:273:in `parse': Do not allow except col_sep_split_separator after quoted fields in line 1. (CSV::MalformedCSVError)

Ruby 2.5

$ ruby -v t.rb
ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-darwin18]
[["a", "\"b\""]]

Test code

require 'csv'

csv =<<CSV
a,""b""
CSV

p CSV.parse(csv)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions