ruby-changes:62276
From: Mike <ko1@a...>
Date: Mon, 20 Jul 2020 03:35:18 +0900 (JST)
Subject: [ruby-changes:62276] d57bc03ba9 (master): [ruby/csv] Do not loop forever when skip_lines regexp matches zero length with anchors (#110)
https://git.ruby-lang.org/ruby.git/commit/?id=d57bc03ba9 From d57bc03ba98649661c7dedbb46ec2f2bb6bee9be Mon Sep 17 00:00:00 2001 From: Mike MacDonald <crazymykl@g...> Date: Sat, 2 Nov 2019 23:48:22 -0400 Subject: [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 diff --git a/lib/csv/parser.rb b/lib/csv/parser.rb index 42145f8..f30cfc6 100644 --- a/lib/csv/parser.rb +++ b/lib/csv/parser.rb @@ -769,7 +769,7 @@ class CSV https://github.com/ruby/ruby/blob/trunk/lib/csv/parser.rb#L769 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 196858f..2f7e6c8 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 https://github.com/ruby/ruby/blob/trunk/test/csv/parse/test_skip_lines.rb#L102 :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 -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/