smarter_csv 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 430c575cd14bb098e7754d0228186f0a29007495
4
- data.tar.gz: 903d566d2c3569c954ecabf5ebf310c8f9aa5234
3
+ metadata.gz: cbd937d958dbb95653e9368a6b10075162f122e7
4
+ data.tar.gz: eaf5a03e4a209900189f035d2b5b876cc1c08e51
5
5
  SHA512:
6
- metadata.gz: c846301856cbcf8e76efcf42d1d532a3317e6fdfce9ca06577794bae11b1e739086c6d40df70210fd3f0c75836bb9265ccff4d6d286fa998af735d43ef5c46ae
7
- data.tar.gz: 52274d68e87f3e194be610bd69cfee6b084c193e389cf3591399a70e4051f23d1a2206c4d61aadb25c6c63c8675f285ef343e022f9dc70c95aac518f849ed005
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] == 'utf-8'
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] == 'utf-8'
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
@@ -1,3 +1,3 @@
1
1
  module SmarterCSV
2
- VERSION = "1.1.2"
2
+ VERSION = "1.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smarter_csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - |