summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Frank <flori@ping.de>2015-06-13 12:45:28 +0200
committerFlorian Frank <flori@ping.de>2015-06-13 12:45:28 +0200
commit280005f5bc5e8e120f7ed717f7a86eaad2dae6b4 (patch)
treea7161fe598c2c53e8a3870797040d4d26fa90cb2
parent7ebd90f611841c7ee94471f3287ff7d79223be45 (diff)
downloadjson-280005f5bc5e8e120f7ed717f7a86eaad2dae6b4.tar.gz
Remove byte sniffing from Pure::Parser
-rw-r--r--lib/json/pure/parser.rb34
1 files changed, 1 insertions, 33 deletions
diff --git a/lib/json/pure/parser.rb b/lib/json/pure/parser.rb
index a41d1ee..9e40eb7 100644
--- a/lib/json/pure/parser.rb
+++ b/lib/json/pure/parser.rb
@@ -152,40 +152,8 @@ module JSON
raise TypeError, "#{source.inspect} is not like a string"
end
if defined?(::Encoding)
- if source.encoding == ::Encoding::ASCII_8BIT
- b = source[0, 4].bytes.to_a
- source =
- case
- when b.size >= 4 && b[0] == 0 && b[1] == 0 && b[2] == 0
- source.dup.force_encoding(::Encoding::UTF_32BE).encode!(::Encoding::UTF_8)
- when b.size >= 4 && b[0] == 0 && b[2] == 0
- source.dup.force_encoding(::Encoding::UTF_16BE).encode!(::Encoding::UTF_8)
- when b.size >= 4 && b[1] == 0 && b[2] == 0 && b[3] == 0
- source.dup.force_encoding(::Encoding::UTF_32LE).encode!(::Encoding::UTF_8)
- when b.size >= 4 && b[1] == 0 && b[3] == 0
- source.dup.force_encoding(::Encoding::UTF_16LE).encode!(::Encoding::UTF_8)
- else
- source.dup
- end
- else
- source = source.encode(::Encoding::UTF_8)
- end
+ source = source.encode(::Encoding::UTF_8)
source.force_encoding(::Encoding::ASCII_8BIT)
- else
- b = source
- source =
- case
- when b.size >= 4 && b[0] == 0 && b[1] == 0 && b[2] == 0
- JSON.iconv('utf-8', 'utf-32be', b)
- when b.size >= 4 && b[0] == 0 && b[2] == 0
- JSON.iconv('utf-8', 'utf-16be', b)
- when b.size >= 4 && b[1] == 0 && b[2] == 0 && b[3] == 0
- JSON.iconv('utf-8', 'utf-32le', b)
- when b.size >= 4 && b[1] == 0 && b[3] == 0
- JSON.iconv('utf-8', 'utf-16le', b)
- else
- b
- end
end
source
end