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

[ruby/csv] Do not loop forever when skip_lines regexp matches zero length with anchors (#110)

* Do not loop forever when skip_lines regexp matches zero length with anchors

* Remove needless white spaces

* Add missing eos check in skip_needless_lines

* Simplify test

https://github.com/ruby/csv/commit/3b15d4a3e8
This commit is contained in:
Mike MacDonald 2019-11-02 23:48:22 -04:00 committed by Nobuyoshi Nakada
parent b219cd5ac3
commit d57bc03ba9
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6
Notes: git 2020-07-20 03:35:48 +09:00
2 changed files with 8 additions and 1 deletions

View file

@ -769,7 +769,7 @@ class CSV
def skip_needless_lines
return unless @skip_lines
while true
until @scanner.eos?
@scanner.keep_start
line = @scanner.scan_all(@not_line_end) || "".encode(@encoding)
line << @row_separator if parse_row_end

View file

@ -102,4 +102,11 @@ class TestCSVParseSkipLines < Test::Unit::TestCase
:skip_lines => /\A#/))
end
end
def test_empty_line_and_liberal_parsing
assert_equal([["a", "b"]],
CSV.parse("a,b\n",
:liberal_parsing => true,
:skip_lines => /^$/))
end
end