aboutsummaryrefslogtreecommitdiffstats
path: root/lib/csv.rb
diff options
context:
space:
mode:
authorjeg2 <jeg2@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-25 14:46:08 +0000
committerjeg2 <jeg2@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-25 14:46:08 +0000
commit6e7544f132d2903cf88f7f41208913d940068be8 (patch)
treed792df6c66688255fc3124792efed82f6ce1f735 /lib/csv.rb
parentce9d84a9f05c2bc891826aa87cc38faac1a1c5b8 (diff)
downloadruby-6e7544f132d2903cf88f7f41208913d940068be8.tar.gz
* lib/csv.rb: Improved stray quoting error message (patch by Edvard Majakari).
* lib/csv.rb: Remove debugging prints. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31735 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/csv.rb')
-rw-r--r--lib/csv.rb35
1 files changed, 21 insertions, 14 deletions
diff --git a/lib/csv.rb b/lib/csv.rb
index ce5fdeaa61..c19a59e997 100644
--- a/lib/csv.rb
+++ b/lib/csv.rb
@@ -1567,23 +1567,24 @@ class CSV
@io = data.is_a?(String) ? StringIO.new(data) : data
# honor the IO encoding if we can, otherwise default to ASCII-8BIT
@encoding = raw_encoding(nil) ||
- (if encoding = options.delete(:internal_encoding)
- case encoding
- when Encoding; encoding
- else Encoding.find(encoding)
- end
- end) ||
- (case encoding = options.delete(:encoding)
- when Encoding; encoding
- when /\A[^:]+/; Encoding.find($&)
- end) ||
+ ( if encoding = options.delete(:internal_encoding)
+ case encoding
+ when Encoding; encoding
+ else Encoding.find(encoding)
+ end
+ end ) ||
+ ( case encoding = options.delete(:encoding)
+ when Encoding; encoding
+ when /\A[^:]+/; Encoding.find($&)
+ end ) ||
Encoding.default_internal || Encoding.default_external
#
# prepare for building safe regular expressions in the target encoding,
# if we can transcode the needed characters
#
@re_esc = "\\".encode(@encoding) rescue ""
- @re_chars = /#{%"[-][\\.^$?*+{}()|# \r\n\t\f\v]".encode(@encoding, fallback: proc{""})}/
+ @re_chars = /#{%"[-][\\.^$?*+{}()|# \r\n\t\f\v]".encode(@encoding)}/
+ # @re_chars = /#{%"[-][\\.^$?*+{}()|# \r\n\t\f\v]".encode(@encoding, fallback: proc{""})}/
init_separators(options)
init_parsers(options)
@@ -1884,7 +1885,10 @@ class CSV
if part[-1] == @quote_char && part.count(@quote_char) % 2 != 0
# extended column ends
csv.last << part[0..-2]
- raise MalformedCSVError if csv.last =~ @parsers[:stray_quote]
+ if csv.last =~ @parsers[:stray_quote]
+ raise MalformedCSVError,
+ "Missing or stray quote in line #{lineno + 1}"
+ end
csv.last.gsub!(@quote_char * 2, @quote_char)
in_extended_col = false
else
@@ -1901,7 +1905,10 @@ class CSV
else
# regular quoted column
csv << part[1..-2]
- raise MalformedCSVError if csv.last =~ @parsers[:stray_quote]
+ if csv.last =~ @parsers[:stray_quote]
+ raise MalformedCSVError,
+ "Missing or stray quote in line #{lineno + 1}"
+ end
csv.last.gsub!(@quote_char * 2, @quote_char)
end
elsif part =~ @parsers[:quote_or_nl]
@@ -1910,7 +1917,7 @@ class CSV
raise MalformedCSVError, "Unquoted fields do not allow " +
"\\r or \\n (line #{lineno + 1})."
else
- raise MalformedCSVError, "Illegal quoting on line #{lineno + 1}."
+ raise MalformedCSVError, "Illegal quoting in line #{lineno + 1}."
end
else
# Regular ole unquoted field.