Actions
Feature #9147
closedCSV.new option skip_lines should escape String before convert to Regexp
Description
After r43823, the following script ignore all lines.
== test_csv.rb ==
require "csv"
csv = CSV.new(<<-EOL, skip_lines: ".")
1,foo
.2,bar
3,baz
EOL
p csv.each.to_a # => []
I think String value for skip_lines option should be escaped before convert to Regexp.
diff --git a/lib/csv.rb b/lib/csv.rb
index a4d8e3d..3e067f2 100644
--- a/lib/csv.rb
+++ b/lib/csv.rb
@@ -2127,7 +2127,7 @@ class CSV
# See also CSV.new
def init_comments(options)
@skip_lines = options.delete(:skip_lines)
- @skip_lines = Regexp.new(@skip_lines) if @skip_lines.is_a? String
+ @skip_lines = Regexp.new(Regexp.escape(@skip_lines)) if @skip_lines.is_a? String
if @skip_lines and not @skip_lines.respond_to?(:match)
raise ArgumentError, ":skip_lines has to respond to matches"
end
Actions
Like0
Like0Like0Like0Like0