gigo 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
- remote: /Users/kencollins/Repositories/gigo
2
+ remote: /Users/kencollins/Repositories/customink/gigo
3
3
  specs:
4
- gigo (1.0.0)
4
+ gigo (1.1.0)
5
5
  activesupport (>= 3.0)
6
6
  ensure_valid_encoding (~> 0.5.3)
7
7
 
@@ -13,9 +13,9 @@ GEM
13
13
  bundler
14
14
  rake
15
15
  ensure_valid_encoding (0.5.3)
16
- minitest (4.6.1)
16
+ minitest (4.7.0)
17
17
  minitest-emoji (1.0.0)
18
- rake (10.0.3)
18
+ rake (10.0.4)
19
19
 
20
20
  PLATFORMS
21
21
  ruby
@@ -1,7 +1,7 @@
1
1
  PATH
2
- remote: /Users/kencollins/Repositories/gigo
2
+ remote: /Users/kencollins/Repositories/customink/gigo
3
3
  specs:
4
- gigo (1.0.0)
4
+ gigo (1.1.0)
5
5
  activesupport (>= 3.0)
6
6
  ensure_valid_encoding (~> 0.5.3)
7
7
 
@@ -14,10 +14,10 @@ GEM
14
14
  bundler
15
15
  rake
16
16
  ensure_valid_encoding (0.5.3)
17
- minitest (4.6.1)
17
+ minitest (4.7.0)
18
18
  minitest-emoji (1.0.0)
19
19
  multi_json (1.2.0)
20
- rake (10.0.3)
20
+ rake (10.0.4)
21
21
 
22
22
  PLATFORMS
23
23
  ruby
@@ -1,25 +1,25 @@
1
1
  PATH
2
- remote: /Users/kencollins/Repositories/gigo
2
+ remote: /Users/kencollins/Repositories/customink/gigo
3
3
  specs:
4
- gigo (1.0.0)
4
+ gigo (1.1.0)
5
5
  activesupport (>= 3.0)
6
6
  ensure_valid_encoding (~> 0.5.3)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (3.2.12)
12
- i18n (~> 0.6)
11
+ activesupport (3.2.13)
12
+ i18n (= 0.6.1)
13
13
  multi_json (~> 1.0)
14
14
  appraisal (0.5.1)
15
15
  bundler
16
16
  rake
17
17
  ensure_valid_encoding (0.5.3)
18
18
  i18n (0.6.1)
19
- minitest (4.6.1)
19
+ minitest (4.7.0)
20
20
  minitest-emoji (1.0.0)
21
- multi_json (1.6.1)
22
- rake (10.0.3)
21
+ multi_json (1.7.2)
22
+ rake (10.0.4)
23
23
 
24
24
  PLATFORMS
25
25
  ruby
@@ -1,18 +1,18 @@
1
1
  GIT
2
2
  remote: git://github.com/rails/rails.git
3
- revision: 23048551fdb679e694d8245e9f8c969ed7a71f40
3
+ revision: b6e5971e53746a79abc92ce9acea85ca14fab0b3
4
4
  specs:
5
- activesupport (4.0.0.beta)
6
- i18n (~> 0.6)
5
+ activesupport (4.0.0.beta1)
6
+ i18n (~> 0.6, >= 0.6.4)
7
7
  minitest (~> 4.2)
8
8
  multi_json (~> 1.3)
9
9
  thread_safe (~> 0.1)
10
- tzinfo (~> 0.3.33)
10
+ tzinfo (~> 0.3.37)
11
11
 
12
12
  PATH
13
- remote: /Users/kencollins/Repositories/gigo
13
+ remote: /Users/kencollins/Repositories/customink/gigo
14
14
  specs:
15
- gigo (1.0.0)
15
+ gigo (1.1.0)
16
16
  activesupport (>= 3.0)
17
17
  ensure_valid_encoding (~> 0.5.3)
18
18
 
@@ -24,14 +24,14 @@ GEM
24
24
  rake
25
25
  atomic (1.0.1)
26
26
  ensure_valid_encoding (0.5.3)
27
- i18n (0.6.1)
28
- minitest (4.6.1)
27
+ i18n (0.6.4)
28
+ minitest (4.7.0)
29
29
  minitest-emoji (1.0.0)
30
- multi_json (1.6.1)
31
- rake (10.0.3)
30
+ multi_json (1.7.2)
31
+ rake (10.0.4)
32
32
  thread_safe (0.1.0)
33
33
  atomic
34
- tzinfo (0.3.35)
34
+ tzinfo (0.3.37)
35
35
 
36
36
  PLATFORMS
37
37
  ruby
data/lib/gigo.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'active_support/multibyte'
1
2
  require 'active_support/core_ext/object/acts_like'
2
3
  require 'active_support/core_ext/string/behavior'
3
4
  require 'ensure_valid_encoding'
@@ -19,10 +20,14 @@ module GIGO
19
20
  def self.safe_detect_and_encoder(data)
20
21
  string = data
21
22
  begin
22
- encoding = CharDet.detect(string.dup)['encoding'] || string.encoding || Encoding.default_internal || forced_encoding
23
- string = string.force_encoding(encoding).encode forced_encoding, :undef => :replace, :invalid => :replace
23
+ string = ActiveSupport::Multibyte.proxy_class.new(string).tidy_bytes
24
24
  rescue Exception => e
25
- string = string.encode forced_encoding, :undef => :replace, :invalid => :replace
25
+ begin
26
+ encoding = CharDet.detect(string.dup)['encoding'] || string.encoding || Encoding.default_internal || forced_encoding
27
+ string = string.force_encoding(encoding).encode forced_encoding, :undef => :replace, :invalid => :replace
28
+ rescue Exception => e
29
+ string = string.encode forced_encoding, :undef => :replace, :invalid => :replace
30
+ end
26
31
  end
27
32
  EnsureValidEncoding.ensure_valid_encoding string, invalid: :replace, replace: "?"
28
33
  end
data/lib/gigo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module GIGO
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -10,6 +10,7 @@ module GIGO
10
10
  let(:data_utf8) { "€20 – “Woohoo”" }
11
11
  let(:data_bad_readin) { "�20 � �Woohoo�" }
12
12
  let(:data_cp1252) { data_utf8.encode('CP1252') }
13
+ let(:data_bin_apos) { "won\x92t".force_encoding('binary') }
13
14
  let(:data_really_bad) { "ed.Ã\u0083Ã\u0083\xC3" }
14
15
 
15
16
 
@@ -22,6 +23,10 @@ module GIGO
22
23
  GIGO.load(o).must_equal o
23
24
  end
24
25
 
26
+ it 'fixes windows apostrophe' do
27
+ GIGO.load(data_bin_apos).must_equal "won’t"
28
+ end
29
+
25
30
  it 'should allows properly encoded and marked strings to be passed thru' do
26
31
  GIGO.load(data_utf8).must_equal data_utf8
27
32
  GIGO.load(data_utf8_emoji).must_equal data_utf8_emoji
@@ -32,7 +37,7 @@ module GIGO
32
37
  end
33
38
 
34
39
  it 'allows really bad data to be encoded using default replace and question marks' do
35
- GIGO.load(data_utf8_emoji.force_encoding('ASCII-8BIT')).must_equal '����'
40
+ GIGO.load(data_utf8_emoji.force_encoding('ASCII-8BIT')).must_equal data_utf8_emoji
36
41
  end
37
42
 
38
43
  it 'converts windows codepages that are poorly marked as another encoding' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gigo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -183,7 +183,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
183
183
  version: '0'
184
184
  segments:
185
185
  - 0
186
- hash: -1651701888858574901
186
+ hash: 2152698803205983593
187
187
  required_rubygems_version: !ruby/object:Gem::Requirement
188
188
  none: false
189
189
  requirements:
@@ -192,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
192
  version: '0'
193
193
  segments:
194
194
  - 0
195
- hash: -1651701888858574901
195
+ hash: 2152698803205983593
196
196
  requirements: []
197
197
  rubyforge_project:
198
198
  rubygems_version: 1.8.25