1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/csv] Changed line ending handling to consider the combination \r\n as a single entry when row is faulty (https://github.com/ruby/csv/pull/220)

29cef9ea9d
This commit is contained in:
Joakim Antman 2021-10-03 22:10:48 +03:00 committed by Sutou Kouhei
parent 39ecdabe67
commit 7f3dd601c8
Notes: git 2021-10-24 05:58:04 +09:00
2 changed files with 17 additions and 4 deletions

View file

@ -526,7 +526,7 @@ class CSV
@cr = "\r".encode(@encoding)
@lf = "\n".encode(@encoding)
@cr_or_lf = Regexp.new("[\r\n]".encode(@encoding))
@line_end = Regexp.new("\r\n|\n|\r".encode(@encoding))
@not_line_end = Regexp.new("[^\r\n]+".encode(@encoding))
end
@ -914,7 +914,7 @@ class CSV
message = "Any value after quoted field isn't allowed"
raise MalformedCSVError.new(message, @lineno)
elsif @unquoted_column_value and
(new_line = @scanner.scan(@cr_or_lf))
(new_line = @scanner.scan(@line_end))
ignore_broken_line
message = "Unquoted fields do not allow new line " +
"<#{new_line.inspect}>"
@ -923,7 +923,7 @@ class CSV
ignore_broken_line
message = "Illegal quoting"
raise MalformedCSVError.new(message, @lineno)
elsif (new_line = @scanner.scan(@cr_or_lf))
elsif (new_line = @scanner.scan(@line_end))
ignore_broken_line
message = "New line must be <#{@row_separator.inspect}> " +
"not <#{new_line.inspect}>"
@ -1089,7 +1089,7 @@ class CSV
def ignore_broken_line
@scanner.scan_all(@not_line_end)
@scanner.scan_all(@cr_or_lf)
@scanner.scan_all(@line_end)
@lineno += 1
end