Project

General

Profile

Bug #8405

Updated by nobu (Nobuyoshi Nakada) almost 7 years ago

=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: ((*CSV::MalformedCSVError: Missing or stray quote in line xxx})) 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: 

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

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

Back