Skip to content

Commit 3b15d4a

Browse files
crazymyklkou
authored andcommitted
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
1 parent 64a1ea0 commit 3b15d4a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/csv/parser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ def build_scanner
769769
def skip_needless_lines
770770
return unless @skip_lines
771771

772-
while true
772+
until @scanner.eos?
773773
@scanner.keep_start
774774
line = @scanner.scan_all(@not_line_end) || "".encode(@encoding)
775775
line << @row_separator if parse_row_end

test/csv/parse/test_skip_lines.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,11 @@ def test_multibyte_data
102102
:skip_lines => /\A#/))
103103
end
104104
end
105+
106+
def test_empty_line_and_liberal_parsing
107+
assert_equal([["a", "b"]],
108+
CSV.parse("a,b\n",
109+
:liberal_parsing => true,
110+
:skip_lines => /^$/))
111+
end
105112
end

0 commit comments

Comments
 (0)