Skip to content

Commit 280005f

Browse files
committed
Remove byte sniffing from Pure::Parser
1 parent 7ebd90f commit 280005f

1 file changed

Lines changed: 1 addition & 33 deletions

File tree

lib/json/pure/parser.rb

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -152,40 +152,8 @@ def convert_encoding(source)
152152
raise TypeError, "#{source.inspect} is not like a string"
153153
end
154154
if defined?(::Encoding)
155-
if source.encoding == ::Encoding::ASCII_8BIT
156-
b = source[0, 4].bytes.to_a
157-
source =
158-
case
159-
when b.size >= 4 && b[0] == 0 && b[1] == 0 && b[2] == 0
160-
source.dup.force_encoding(::Encoding::UTF_32BE).encode!(::Encoding::UTF_8)
161-
when b.size >= 4 && b[0] == 0 && b[2] == 0
162-
source.dup.force_encoding(::Encoding::UTF_16BE).encode!(::Encoding::UTF_8)
163-
when b.size >= 4 && b[1] == 0 && b[2] == 0 && b[3] == 0
164-
source.dup.force_encoding(::Encoding::UTF_32LE).encode!(::Encoding::UTF_8)
165-
when b.size >= 4 && b[1] == 0 && b[3] == 0
166-
source.dup.force_encoding(::Encoding::UTF_16LE).encode!(::Encoding::UTF_8)
167-
else
168-
source.dup
169-
end
170-
else
171-
source = source.encode(::Encoding::UTF_8)
172-
end
155+
source = source.encode(::Encoding::UTF_8)
173156
source.force_encoding(::Encoding::ASCII_8BIT)
174-
else
175-
b = source
176-
source =
177-
case
178-
when b.size >= 4 && b[0] == 0 && b[1] == 0 && b[2] == 0
179-
JSON.iconv('utf-8', 'utf-32be', b)
180-
when b.size >= 4 && b[0] == 0 && b[2] == 0
181-
JSON.iconv('utf-8', 'utf-16be', b)
182-
when b.size >= 4 && b[1] == 0 && b[2] == 0 && b[3] == 0
183-
JSON.iconv('utf-8', 'utf-32le', b)
184-
when b.size >= 4 && b[1] == 0 && b[3] == 0
185-
JSON.iconv('utf-8', 'utf-16le', b)
186-
else
187-
b
188-
end
189157
end
190158
source
191159
end

0 commit comments

Comments
 (0)