Project

General

Profile

Bug #8405

CSV module - improper regexp for escaping special characters

Added by dunric (David Unric) over 4 years ago. Updated over 3 years ago.

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

Description

=begin
There seems to be bug in csv.rb module. If you would like to use some special characters like (({|})) as a quote_char (passed as a parameter to CSV methods like read), program terminates with (({CSV::MalformedCSVError: Missing or stray quote in line xxx})) error message even if the input .csv file is correct.

Bellow is the assignment of the Regexp used for escaping special symbols used in regular expressions:

1587: @re_chars = /#{%"[-][\.$?*+{}()|# \r\n\t\f\v]".encode(@encoding)}/

The issue is with the leading (({[-]})) which I find completely wrong and causes miss of all matches it was intended to. The hyphen char "(({-}))" has to be escaped only inside brackets (({[]})) and only if it does not immediately follow the left bracket.

The quick fix for the above issue may look like

1587: @re_chars = /#{%"(?<!\[)-(?=.\])|[\.$?+{}()|# \r\n\t\f\v]".encode(@encoding)}/

I'd like to mention it would also match strings including right bracket without its left counterpart but it doesn't matter anyway. Lookbehind doesn't support quantifiers in Ruby so it would require to rewrite whole substitution code where applied.
=end

Associated revisions

Revision 45374
Added by JEG2 (James Gray) over 3 years ago

  • lib/csv.rb: Fixed a broken regular expression that was causing CSV to miss escaping some special meaning characters when used in parsing. Reported by David Unric [Bug #8405]

Revision 45374
Added by JEG2 (James Gray) over 3 years ago

  • lib/csv.rb: Fixed a broken regular expression that was causing CSV to miss escaping some special meaning characters when used in parsing. Reported by David Unric [Bug #8405]

Revision 45374
Added by JEG2 (James Gray) over 3 years ago

  • lib/csv.rb: Fixed a broken regular expression that was causing CSV to miss escaping some special meaning characters when used in parsing. Reported by David Unric [Bug #8405]

Revision 45374
Added by JEG2 (James Gray) over 3 years ago

  • lib/csv.rb: Fixed a broken regular expression that was causing CSV to miss escaping some special meaning characters when used in parsing. Reported by David Unric [Bug #8405]

Revision 45956
Added by nagachika (Tomoyuki Chikanaga) over 3 years ago

merge revision(s) r45374: [Backport #8405]

* lib/csv.rb: Fixed a broken regular expression that was causing
  CSV to miss escaping some special meaning characters when used
  in parsing.
  Reported by David Unric
   [Bug #8405]

History

#1 [ruby-core:54987] Updated by nobu (Nobuyoshi Nakada) over 4 years ago

  • Description updated (diff)
  • Status changed from Open to Assigned
  • Assignee set to JEG2 (James Gray)

#2 [ruby-core:54989] Updated by naruse (Yui NARUSE) over 4 years ago

  • Target version set to 2.1.0

#3 [ruby-core:60295] Updated by hsbt (Hiroshi SHIBATA) over 3 years ago

  • Target version changed from 2.1.0 to 2.2.0

#4 [ruby-core:61612] Updated by JEG2 (James Gray) over 3 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

Applied in changeset r45374.


  • lib/csv.rb: Fixed a broken regular expression that was causing CSV to miss escaping some special meaning characters when used in parsing. Reported by David Unric [Bug #8405]

#5 [ruby-core:61621] Updated by nagachika (Tomoyuki Chikanaga) over 3 years ago

  • Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN to 1.9.3: REQUIRED, 2.0.0: REQUIRED, 2.1: REQUIRED

#6 [ruby-core:61768] Updated by nagachika (Tomoyuki Chikanaga) over 3 years ago

  • Backport changed from 1.9.3: REQUIRED, 2.0.0: REQUIRED, 2.1: REQUIRED to 1.9.3: REQUIRED, 2.0.0: DONE, 2.1: REQUIRED

r45374 was backported to ruby_2_0_0 at r45476.

#7 [ruby-core:62607] Updated by nagachika (Tomoyuki Chikanaga) over 3 years ago

  • Backport changed from 1.9.3: REQUIRED, 2.0.0: DONE, 2.1: REQUIRED to 1.9.3: REQUIRED, 2.0.0: DONE, 2.1: DONE

r45374 was backported into ruby2_1 branch at r45956.

Also available in: Atom PDF