guess_html_encoding 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- guess_html_encoding (0.0.5)
4
+ guess_html_encoding (0.0.6)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -1,3 +1,3 @@
1
1
  module GuessHtmlEncoding
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -29,7 +29,7 @@ module GuessHtmlEncoding
29
29
  out = "UTF-8" if %w[DEFAULT UTF8 UNICODE].include?(out)
30
30
  out = "CP1251" if out == "CP-1251"
31
31
  out = "ISO-8859-1" if %w[LATIN1 LATIN-1].include?(out)
32
- out = "Windows-1250" if %w[WIN-1251 WIN1251].include?(out)
32
+ out = "WINDOWS-1250" if %w[WIN-1251 WIN1251].include?(out)
33
33
  end
34
34
 
35
35
  out
@@ -49,6 +49,6 @@ module GuessHtmlEncoding
49
49
 
50
50
  # Is this encoding loaded?
51
51
  def self.encoding_loaded?(encoding)
52
- Encoding.name_list.include? encoding
52
+ !!Encoding.find(encoding) rescue nil
53
53
  end
54
54
  end
@@ -47,6 +47,11 @@ describe "GuessHtmlEncoding" do
47
47
  guess.should == "UTF-8"
48
48
  end
49
49
 
50
+ it "translates WIN1251 to WINDOWS-1250" do
51
+ guess = GuessHtmlEncoding.guess('<html><head><meta http-equiv="content-type" content="text/html; charset=WIN1251;"></head><body><div>hi!</div></body></html>')
52
+ guess.should == "WINDOWS-1250"
53
+ end
54
+
50
55
  it "should not raise an exception if data is nil" do
51
56
  GuessHtmlEncoding.guess(nil).should_not raise_error(TypeError)
52
57
  end
@@ -100,8 +105,28 @@ describe "GuessHtmlEncoding" do
100
105
 
101
106
  describe "#encoding_loaded?" do
102
107
  it 'returns true for all loaded encodings' do
103
- Encoding.name_list.each do |name|
108
+ (Encoding.name_list - ["internal"]).each do |name|
104
109
  GuessHtmlEncoding.encoding_loaded?(name).should be_true
110
+ lambda { Encoding.find(name) }.should_not raise_error
111
+ end
112
+ end
113
+
114
+ it 'returns true for uppercase encodings' do
115
+ GuessHtmlEncoding.encoding_loaded?("WINDOWS-1250").should be_true
116
+ lambda { Encoding.find("WINDOWS-1250") }.should_not raise_error
117
+ end
118
+
119
+ it 'returns true for lowercase encodings' do
120
+ GuessHtmlEncoding.encoding_loaded?("windows-1250").should be_true
121
+ lambda { Encoding.find("windows-1250") }.should_not raise_error
122
+ end
123
+
124
+ it 'returns true for encoding aliases' do
125
+ Encoding.aliases.keys.each do |key|
126
+ GuessHtmlEncoding.encoding_loaded?(key).should be_true
127
+ GuessHtmlEncoding.encoding_loaded?(key.upcase).should be_true
128
+ lambda { Encoding.find(key) }.should_not raise_error
129
+ lambda { Encoding.find(key.upcase) }.should_not raise_error
105
130
  end
106
131
  end
107
132
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guess_html_encoding
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-24 00:00:00.000000000 Z
12
+ date: 2012-09-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec