Skip to content

Commit 415953c

Browse files
authored
Merge pull request #483 from notEthan/unicode_mixed
bugfix json/pure mixing escaped with literal unicode raises Encoding::CompatibilityError
2 parents 5d9d8f3 + 766f816 commit 415953c

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/json/pure/parser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def parse_string
179179
bytes << c[6 * i + 2, 2].to_i(16) << c[6 * i + 4, 2].to_i(16)
180180
i += 1
181181
end
182-
JSON.iconv('utf-8', 'utf-16be', bytes)
182+
JSON.iconv('utf-8', 'utf-16be', bytes).force_encoding(::Encoding::ASCII_8BIT)
183183
end
184184
end
185185
if string.respond_to?(:force_encoding)

tests/json_parser_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ def test_parse_bigdecimals
115115
assert_equal(BigDecimal("0.901234567890123456789E1"),JSON.parse('{"foo": 9.01234567890123456789}', decimal_class: BigDecimal)["foo"] )
116116
end
117117

118+
def test_parse_string_mixed_unicode
119+
assert_equal(["éé"], JSON.parse("[\"\\u00e9é\"]"))
120+
end
121+
118122
if Array.method_defined?(:permutation)
119123
def test_parse_more_complex_arrays
120124
a = [ nil, false, true, "foßbar", [ "n€st€d", true ], { "nested" => true, "n€ßt€ð2" => {} }]

0 commit comments

Comments
 (0)