Skip to content
Browse files

Add line number to error message.

  • Loading branch information...
1 parent edfc3e0 commit cd9c813fa07fb1c25836fe3735b60c88cba9d165 @JEG2 committed May 25, 2011
Showing with 7 additions and 4 deletions.
  1. +1 −0 CHANGELOG
  2. +5 −3 lib/faster_csv.rb
  3. +1 −1 test/tc_csv_parsing.rb
View
1 CHANGELOG
@@ -5,6 +5,7 @@ Below is a complete listing of changes for each revision of FasterCSV.
== 1.5.5
* Removed setup.rb due to licensing concerns.
+* Improved stray quoting error message (patch by Edvard Majakari).
== 1.5.4
View
8 lib/faster_csv.rb
@@ -1642,8 +1642,10 @@ def shift
field_quotes += match.count(@quote_char)
if field_quotes % 2 == 0
in_quotes = current_field[@parsers[:quoted_field], 1]
- raise MalformedCSVError if !in_quotes ||
- in_quotes[@parsers[:stray_quote]]
+ if !in_quotes || in_quotes[@parsers[:stray_quote]]
+ raise MalformedCSVError,
+ "Missing or stray quote in line #{lineno + 1}"
+ end
current_field = in_quotes
current_field.gsub!(@quote_char * 2, @quote_char) # unescape contents
csv << current_field
@@ -1653,7 +1655,7 @@ def shift
current_field << @col_sep
end
elsif match.count("\r\n").zero?
- raise MalformedCSVError, "Illegal quoting on line #{lineno + 1}."
+ raise MalformedCSVError, "Illegal quoting in line #{lineno + 1}."
else
raise MalformedCSVError, "Unquoted fields do not allow " +
"\\r or \\n (line #{lineno + 1})."
View
2 test/tc_csv_parsing.rb
@@ -185,7 +185,7 @@ def test_malformed_csv
assert_send([csv.lineno, :<, 4])
end
rescue FasterCSV::MalformedCSVError
- assert_equal("Illegal quoting on line 4.", $!.message)
+ assert_equal("Illegal quoting in line 4.", $!.message)
end
end
end

0 comments on commit cd9c813

Please sign in to comment.
Something went wrong with that request. Please try again.