smarter_csv 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/smarter_csv/smarter_csv.rb +6 -2
- data/lib/smarter_csv/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbd937d958dbb95653e9368a6b10075162f122e7
|
4
|
+
data.tar.gz: eaf5a03e4a209900189f035d2b5b876cc1c08e51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7abffcc904a90122851159a5d241ad0f5944c0b3c67a288c5f91f93c86667f3ce0293cbb14dbe5d8c507a8ed955d8583d39099431ec929ba0d822b163a3e0ff1
|
7
|
+
data.tar.gz: a96735123fb0c8f5dae9eeea4b7606feba984d6daa6f347125a2cd6a810cb5a3eecf3af733277f4ee8143077b08fffbca4ce9a83c0eecccc7972e3a0ce43ef77
|
data/README.md
CHANGED
@@ -293,6 +293,9 @@ Planned in the next releases:
|
|
293
293
|
|
294
294
|
## Changes
|
295
295
|
|
296
|
+
#### 1.1.3 (2016-12-30)
|
297
|
+
* added warning when options indicate UTF-8 processing, but input filehandle is not opened with r:UTF-8 option
|
298
|
+
|
296
299
|
#### 1.1.2 (2016-12-29)
|
297
300
|
* added option `invalid_byte_sequence` (thanks to polycarpou)
|
298
301
|
* added comments on handling of UTF-8 encoding when opening from File vs. OpenURI (thanks to KevinColemanInc)
|
@@ -22,6 +22,10 @@ module SmarterCSV
|
|
22
22
|
begin
|
23
23
|
f = input.respond_to?(:readline) ? input : File.open(input, "r:#{options[:file_encoding]}")
|
24
24
|
|
25
|
+
if (options[:force_utf8] || options[:file_encoding] =~ /utf-8/i) && ( f.respond_to?(:external_encoding) && f.external_encoding != Encoding.find('UTF-8') || f.respond_to?(:encoding) && f.encoding != Encoding.find('UTF-8') )
|
26
|
+
puts 'WARNING: you are trying to process UTF-8 input, but did not open the input with "b:utf-8" option. See README file "NOTES about File Encodings".'
|
27
|
+
end
|
28
|
+
|
25
29
|
if options[:row_sep] == :auto
|
26
30
|
options[:row_sep] = SmarterCSV.guess_line_ending( f, options )
|
27
31
|
f.rewind
|
@@ -36,7 +40,7 @@ module SmarterCSV
|
|
36
40
|
# process the header line in the CSV file..
|
37
41
|
# the first line of a CSV file contains the header .. it might be commented out, so we need to read it anyhow
|
38
42
|
header = f.readline.sub(options[:comment_regexp],'').chomp(options[:row_sep])
|
39
|
-
header = header.encode!('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: options[:invalid_byte_sequence]) if options[:force_utf8] || options[:file_encoding]
|
43
|
+
header = header.encode!('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: options[:invalid_byte_sequence]) if options[:force_utf8] || options[:file_encoding] =~ /utf-8/i
|
40
44
|
|
41
45
|
file_line_count += 1
|
42
46
|
csv_line_count += 1
|
@@ -103,7 +107,7 @@ module SmarterCSV
|
|
103
107
|
line = line.encode!('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '') if options[:force_utf8]
|
104
108
|
|
105
109
|
# replace invalid byte sequence in UTF-8 with question mark to avoid errors
|
106
|
-
line = line.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: options[:invalid_byte_sequence]) if options[:force_utf8] || options[:file_encoding]
|
110
|
+
line = line.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: options[:invalid_byte_sequence]) if options[:force_utf8] || options[:file_encoding] =~ /utf-8/i
|
107
111
|
|
108
112
|
file_line_count += 1
|
109
113
|
csv_line_count += 1
|
data/lib/smarter_csv/version.rb
CHANGED