hippie_csv 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fdb2ee83cfaedb06e0335c4f33c8a022b88dea3e
4
- data.tar.gz: edfcbcf63e127841b3e6ac9906b38330403ce20e
3
+ metadata.gz: 07464f9018551eea7e183ef2ffd0e855b8a46d6a
4
+ data.tar.gz: 98b28c4757768af0fe785127914bdc964a067cff
5
5
  SHA512:
6
- metadata.gz: 40bb630118a2e7ab90ea2e0a4d1627353bcc296296665d34ce0af53286aab4cb11166ffb927ff12b941109146b9969925df8ab59c4cda87ad6fb396ec747e5b6
7
- data.tar.gz: 1f748d3bd1e6900c402aba780daefbb07f02dfaef0912ac4f986058a999f8b420614b0e5d737e3e5c133d23f2bae560932fab95ad60865daa91860f4a56f4e5f
6
+ metadata.gz: 346448b5193bc9beeddee5ec1dfe066a795d0a8820b2dbf28910925bf461feaec1cbbcd886394bf8323d47d931cbfda6e540febe5d5a51935b6fc127c0b61573
7
+ data.tar.gz: ec3278642148bc8597af5d5128fe2c9ac2231fa7b87c19dc40d3a0933ba0a41c0407464bcbe938609e3ea55c72587d39c3c50d56b04c280e4300bd8f5f27e44e
data/README.md CHANGED
@@ -44,8 +44,8 @@ HippieCSV.parse(csv_string)
44
44
 
45
45
  ## Features
46
46
 
47
- - Deduces the delimiter (supports `,`, `;`, and `|`)
48
- - Deduces the quote character (supports `'` and `"`)
47
+ - Deduces the delimiter (supports `,`, `;`, and `\t`)
48
+ - Deduces the quote character (supports `'`, `"`, and `|`)
49
49
  - Forgives backslash escaped quotes in quoted CSVs
50
50
  - Forgives invalid newlines in quoted CSVs
51
51
  - Heals many encoding issues (and aggressively forces UTF-8)
@@ -9,18 +9,7 @@ module HippieCSV
9
9
  end
10
10
 
11
11
  def encode(string)
12
- unless string.valid_encoding?
13
- string = begin
14
- current_encoding = detect_encoding(string)
15
- if !current_encoding.nil?
16
- string.encode(ENCODING, current_encoding)
17
- else
18
- magical_encode(string)
19
- end
20
- rescue Encoding::InvalidByteSequenceError
21
- magical_encode(string)
22
- end
23
- end
12
+ string = ensure_valid_encoding(string)
24
13
 
25
14
  DELIMETERS.each do |delimiter|
26
15
  string.gsub!(blank_line_regex(delimiter), "")
@@ -71,6 +60,20 @@ module HippieCSV
71
60
 
72
61
  private
73
62
 
63
+ def ensure_valid_encoding(string)
64
+ return string if string.valid_encoding?
65
+
66
+ current_encoding = detect_encoding(string)
67
+
68
+ if !current_encoding.nil? && current_encoding != ENCODING
69
+ string.encode(ENCODING, current_encoding)
70
+ else
71
+ magical_encode(string)
72
+ end
73
+ rescue Encoding::InvalidByteSequenceError
74
+ magical_encode(string)
75
+ end
76
+
74
77
  def blank_line_regex(delimiter)
75
78
  /^#{delimiter}+(\r\n|\r)$/
76
79
  end
@@ -1,3 +1,3 @@
1
1
  module HippieCSV
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
@@ -38,6 +38,17 @@ describe HippieCSV::Support do
38
38
  end
39
39
  end
40
40
 
41
+ context "with a string detected to be UTF-8 but with an invalid byte sequence" do
42
+ let(:utf8_string) { ("Rubyのメ" * HippieCSV::ENCODING_SAMPLE_CHARACTER_COUNT).force_encoding("utf-8") }
43
+ let(:string) { utf8_string << "\xBF"}
44
+
45
+ it "ensures encoding becomes valid" do
46
+ expect(string).not_to be_valid_encoding
47
+
48
+ expect(subject.encode(string)).to be_valid_encoding
49
+ end
50
+ end
51
+
41
52
  context 'with unquoted fields and \r or \n' do
42
53
  let(:string) { "id,first_name,last_name\r123,Heinrich,Schütz\r\n" }
43
54
 
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
  describe HippieCSV do
4
4
 
5
5
  it "defines a version" do
6
- expect(HippieCSV::VERSION).to eq("0.0.10")
6
+ expect(HippieCSV::VERSION).to eq("0.0.11")
7
7
  end
8
8
 
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hippie_csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen O'Brien
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-01 00:00:00.000000000 Z
11
+ date: 2017-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  version: '0'
139
139
  requirements: []
140
140
  rubyforge_project:
141
- rubygems_version: 2.2.3
141
+ rubygems_version: 2.5.1
142
142
  signing_key:
143
143
  specification_version: 4
144
144
  summary: Tolerant, liberal CSV parsing
@@ -162,4 +162,3 @@ test_files:
162
162
  - spec/hippie_csv/version_spec.rb
163
163
  - spec/hippie_csv_spec.rb
164
164
  - spec/spec_helper.rb
165
- has_rdoc: