coder 0.1.1 → 0.1.2
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.
- data/lib/coder/cleaner/java.rb +2 -2
- data/lib/coder/cleaner/simple.rb +7 -1
- data/lib/coder/error.rb +1 -1
- data/lib/coder/version.rb +1 -1
- data/spec/coder/cleaner_spec.rb +5 -0
- metadata +1 -1
data/lib/coder/cleaner/java.rb
CHANGED
|
@@ -16,9 +16,9 @@ module Coder
|
|
|
16
16
|
@decoder = @charset.new_decoder
|
|
17
17
|
@decoder.on_malformed_input(::Java::JavaNioCharset::CodingErrorAction::IGNORE)
|
|
18
18
|
@decoder.on_unmappable_character(::Java::JavaNioCharset::CodingErrorAction::IGNORE)
|
|
19
|
-
rescue ::Java::JavaNioCharset::UnsupportedCharsetException
|
|
19
|
+
rescue ::Java::JavaNioCharset::UnsupportedCharsetException, ::Java::JavaNioCharset::IllegalCharsetNameException
|
|
20
20
|
raise Coder::InvalidEncoding, "unknown encoding name - #{encoding}"
|
|
21
|
-
rescue Java::JavaLang::RuntimeException => e
|
|
21
|
+
rescue ::Java::JavaLang::RuntimeException => e
|
|
22
22
|
raise Coder::Error, e.message, e.backtrace
|
|
23
23
|
end
|
|
24
24
|
|
data/lib/coder/cleaner/simple.rb
CHANGED
|
@@ -11,7 +11,7 @@ module Coder
|
|
|
11
11
|
|
|
12
12
|
def initialize(encoding)
|
|
13
13
|
const_name = encoding.to_s.upcase.gsub('-', '_')
|
|
14
|
-
raise Coder::InvalidEncoding, "unknown encoding name - #{encoding}" unless
|
|
14
|
+
raise Coder::InvalidEncoding, "unknown encoding name - #{encoding}" unless coding_available? const_name
|
|
15
15
|
@encoding, @name = Encodings.const_get(const_name), encoding
|
|
16
16
|
end
|
|
17
17
|
|
|
@@ -23,6 +23,12 @@ module Coder
|
|
|
23
23
|
|
|
24
24
|
private
|
|
25
25
|
|
|
26
|
+
def coding_available?(const_name)
|
|
27
|
+
Encodings.const_defined? const_name
|
|
28
|
+
rescue NameError
|
|
29
|
+
false
|
|
30
|
+
end
|
|
31
|
+
|
|
26
32
|
def force_encoding(str)
|
|
27
33
|
return str unless str.respond_to? :force_encoding
|
|
28
34
|
str.force_encoding(@name)
|
data/lib/coder/error.rb
CHANGED
data/lib/coder/version.rb
CHANGED
data/spec/coder/cleaner_spec.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# encoding: UTF-8
|
|
2
2
|
require 'coder/cleaner'
|
|
3
|
+
require 'coder/error'
|
|
3
4
|
|
|
4
5
|
shared_examples Coder::Cleaner do
|
|
5
6
|
let(:encoding) { example.example_group.description }
|
|
@@ -19,6 +20,10 @@ shared_examples Coder::Cleaner do
|
|
|
19
20
|
cleans "{foo \xC3 'bar'}", "{foo 'bar'}"
|
|
20
21
|
cleans "yummy\xE2 \xF0\x9F\x8D\x94 \x9F\x8D\x94", "yummy 🍔 "
|
|
21
22
|
end
|
|
23
|
+
|
|
24
|
+
context "Unknown Encoding" do
|
|
25
|
+
it { expect { subject }.to raise_error(Coder::InvalidEncoding) }
|
|
26
|
+
end
|
|
22
27
|
end
|
|
23
28
|
|
|
24
29
|
describe Coder::Cleaner::Builtin do
|