Skip to content

Commit

Permalink
Fix a bug that the same line is used multiple times
Browse files Browse the repository at this point in the history
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!!!
  • Loading branch information
kou committed Jun 26, 2023
1 parent bfbd6bb commit 183635a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/csv/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ def keep_back
# trace(__method__, :rescan, start, buffer)
string = @scanner.string
if scanner == @scanner
keep = string.byteslice(start, string.bytesize - start)
keep = string.byteslice(start,
string.bytesize - @scanner.pos - start)
else
keep = string
end
Expand Down
8 changes: 8 additions & 0 deletions test/csv/parse/test_skip_lines.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,12 @@ def test_crlf
CSV.parse("a,b\r\n,\r\n",
:skip_lines => /^,+$/))
end

def test_crlf_strip_no_last_crlf
assert_equal([["a"], ["b"]],
CSV.parse("a\r\nb",
row_sep: "\r\n",
skip_lines: /^ *$/,
strip: true))
end
end

0 comments on commit 183635a

Please sign in to comment.