diff --git a/lib/json/pure/parser.rb b/lib/json/pure/parser.rb index e1d701b30..be48c6074 100644 --- a/lib/json/pure/parser.rb +++ b/lib/json/pure/parser.rb @@ -179,7 +179,7 @@ def parse_string bytes << c[6 * i + 2, 2].to_i(16) << c[6 * i + 4, 2].to_i(16) i += 1 end - JSON.iconv('utf-8', 'utf-16be', bytes) + JSON.iconv('utf-8', 'utf-16be', bytes).force_encoding(::Encoding::ASCII_8BIT) end end if string.respond_to?(:force_encoding) diff --git a/tests/json_parser_test.rb b/tests/json_parser_test.rb index 00b254fc6..146ff7c04 100644 --- a/tests/json_parser_test.rb +++ b/tests/json_parser_test.rb @@ -115,6 +115,10 @@ def test_parse_bigdecimals assert_equal(BigDecimal("0.901234567890123456789E1"),JSON.parse('{"foo": 9.01234567890123456789}', decimal_class: BigDecimal)["foo"] ) end + def test_parse_string_mixed_unicode + assert_equal(["éé"], JSON.parse("[\"\\u00e9é\"]")) + end + if Array.method_defined?(:permutation) def test_parse_more_complex_arrays a = [ nil, false, true, "foßbar", [ "n€st€d", true ], { "nested" => true, "n€ßt€ð2" => {} }]