Actions
Bug #19402
closedCSV skip_lines option not behaving as documented
Description
The CSV documentation for the skip_lines
parser option says "If a String, converts it to a Regexp, ignores lines that match it." Application behaviour as well as the source appears to be normalizing the string encoding and running a simple substring check instead. Given the existing behaviour, this might just want a documentation update to describe it accurately?
I stumbled across this on a project still on ruby 2.6.9 (2.6 docs), but it's applicable still at 3.2.0.
Reproduction script:
require 'csv'
data = <<CSV
data,data
test,data
data,test
CSV
puts "Parsing with regexp skip_lines /^test/, expect 2 rows"
CSV.parse(data, skip_lines: /^test/).each { |row| pp row }
puts
puts "Parsing with text skip_lines \"^test\", expect 2 rows"
CSV.parse(data, skip_lines: "^test").each { |row| pp row }
puts
puts "Parsing with unanchored text skip_lines \"test\", expect 1 row"
CSV.parse(data, skip_lines: "test").each { |row| pp row }
puts
$ ruby csv_test.rb
Parsing with regexp skip_lines /^test/, expect 2 rows
["data", "data"]
["data", "test"]
Parsing with text skip_lines "^test", expect 2 rows
["data", "data"]
["test", "data"]
["data", "test"]
Parsing with unanchored text skip_lines "test", expect 1 row
["data", "data"]
Actions
Like0
Like0Like0