diff options
author | Mike MacDonald <crazymykl@gmail.com> | 2019-11-02 23:48:22 -0400 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-07-20 02:32:49 +0900 |
commit | d57bc03ba98649661c7dedbb46ec2f2bb6bee9be (patch) | |
tree | 72fa6a8348b20e640eac893344209cf9d0700f86 | |
parent | b219cd5ac36ffb733e3eccd98d53ecf660dee5bf (diff) |
[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
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3332
-rw-r--r-- | lib/csv/parser.rb | 2 | ||||
-rw-r--r-- | test/csv/parse/test_skip_lines.rb | 7 |
2 files changed, 8 insertions, 1 deletions
diff --git a/lib/csv/parser.rb b/lib/csv/parser.rb index 42145f8923..f30cfc6f76 100644 --- a/lib/csv/parser.rb +++ b/lib/csv/parser.rb @@ -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 diff --git a/test/csv/parse/test_skip_lines.rb b/test/csv/parse/test_skip_lines.rb index 196858f1b0..2f7e6c8ddd 100644 --- a/test/csv/parse/test_skip_lines.rb +++ b/test/csv/parse/test_skip_lines.rb @@ -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 |