Project

General

Profile

Feature #9147

CSV.new option skip_lines should escape String before convert to Regexp

Added by nagachika (Tomoyuki Chikanaga) about 6 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
Target version:
[ruby-core:58549]

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

Associated revisions

Revision 2c69f7b2
Added by hsbt (Hiroshi SHIBATA) over 2 years ago

Escape skip_lines string before convert to Regexp.

It ignored all of lines when given Regexp special characters.

[Feature #9147][ruby-core:58549]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59639 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 59639
Added by hsbt (Hiroshi SHIBATA) over 2 years ago

Escape skip_lines string before convert to Regexp.

It ignored all of lines when given Regexp special characters.

[Feature #9147][ruby-core:58549]

Revision 59639
Added by hsbt (Hiroshi SHIBATA) over 2 years ago

Escape skip_lines string before convert to Regexp.

It ignored all of lines when given Regexp special characters.

[Feature #9147][ruby-core:58549]

Revision 59639
Added by hsbt (Hiroshi SHIBATA) over 2 years ago

Escape skip_lines string before convert to Regexp.

It ignored all of lines when given Regexp special characters.

[Feature #9147][ruby-core:58549]

History

Updated by hsbt (Hiroshi SHIBATA) almost 6 years ago

  • Target version changed from 2.1.0 to 2.2.0
#2

Updated by hsbt (Hiroshi SHIBATA) over 2 years ago

  • Description updated (diff)

Updated by hsbt (Hiroshi SHIBATA) over 2 years ago

  • Assignee changed from JEG2 (James Gray) to hsbt (Hiroshi SHIBATA)
#4

Updated by hsbt (Hiroshi SHIBATA) over 2 years ago

  • Status changed from Assigned to Closed

Applied in changeset trunk|r59639.


Escape skip_lines string before convert to Regexp.

It ignored all of lines when given Regexp special characters.

[Feature #9147][ruby-core:58549]

Also available in: Atom PDF