Skip to content

Stop an empty row separator from matching everywhere - #400

Open
adityawrk wants to merge 2 commits into
ruby:mainfrom
adityawrk:fix/empty-row-separator
Open

adityawrk wants to merge 2 commits into
ruby:mainfrom
adityawrk:fix/empty-row-separator

Conversation

@adityawrk

@adityawrk adityawrk commented Nov 29, 2026 •

Copy link
Copy Markdown

row_sep: "" is one row. The parser built that separator as Regexp.new(""), which is //, so every position counted as the end of a row and parsing never finished:

CSV.parse("a,b\n1,2\n", row_sep: "")
# ["a", "b\n1", "2\n"], then empty rows until the process is killed

An empty separator no longer matches. That input is one row. A field that contains a newline still round-trips, and the documented case with no newline is unchanged:

CSV.parse("foo,0bar,1baz,2", row_sep: "")
# => [["foo", "0bar", "1baz", "2"]]

CSV.generate(row_sep: "") { |csv| csv << ["a", "b\n1", "2"] }
# => "a,\"b\n1\",2"
# parses back to [["a", "b\n1", "2"]]

On csv 3.3.5, a fifth of a second of CSV.parse("a,b\n1,2\n", row_sep: "") produced [["a", "b"], [], [], [], [], []] and was still going. After this change it returns one row. ruby run-test.rb is 536 tests, 4071 assertions.

Fixes #394

CSV.parse with row_sep: "" kept emitting empty rows after the
input, including when a quoted field contained a newline.
Regexp.new("") is //, so the parser treated every position as
the end of a row and never finished the input. An empty
separator is one row and does not match.

Fixes ruby#394

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant