зеркало из https://github.com/github/ruby.git
[ruby/csv] Fix a bug that the same line is used multiple times
GitHub: fix https://github.com/ruby/csv/pull/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!!! https://github.com/ruby/csv/commit/183635ab56
This commit is contained in:
Родитель
539559d36e
Коммит
d6d60d4287
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче