diff --git a/lib/csv/parser.rb b/lib/csv/parser.rb index 3b05132054..ed9297fe30 100644 --- a/lib/csv/parser.rb +++ b/lib/csv/parser.rb @@ -201,7 +201,8 @@ class CSV # 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 diff --git a/test/csv/parse/test_skip_lines.rb b/test/csv/parse/test_skip_lines.rb index d231cc65c3..2fea02eb04 100644 --- a/test/csv/parse/test_skip_lines.rb +++ b/test/csv/parse/test_skip_lines.rb @@ -115,4 +115,12 @@ class TestCSVParseSkipLines < Test::Unit::TestCase 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