Skip to content

Commit 183635a

Browse files
committed
Fix a bug that the same line is used multiple times
GitHub: fix GH-279 It's happen when: * `keep_start`/`keep_{drop,back}` are nested. (e.g.: `strip: true, skip_lines: /.../`) * Row separator is `\r\n`. * `InputScanner` is used. (Small input doesn't use `InputScanner`) Reported by Gabriel Nagy. Thanks!!!
1 parent bfbd6bb commit 183635a

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/csv/parser.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ def keep_back
201201
# trace(__method__, :rescan, start, buffer)
202202
string = @scanner.string
203203
if scanner == @scanner
204-
keep = string.byteslice(start, string.bytesize - start)
204+
keep = string.byteslice(start,
205+
string.bytesize - @scanner.pos - start)
205206
else
206207
keep = string
207208
end

test/csv/parse/test_skip_lines.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,12 @@ def test_crlf
115115
CSV.parse("a,b\r\n,\r\n",
116116
:skip_lines => /^,+$/))
117117
end
118+
119+
def test_crlf_strip_no_last_crlf
120+
assert_equal([["a"], ["b"]],
121+
CSV.parse("a\r\nb",
122+
row_sep: "\r\n",
123+
skip_lines: /^ *$/,
124+
strip: true))
125+
end
118126
end

0 commit comments

Comments
 (0)