summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2022-06-14 07:06:52 +0900
committerGitHub <noreply@github.com>2022-06-14 07:06:52 +0900
commit415953c54c760212844af511515708b676fec866 (patch)
treed62e433b283ffc4dd5da20d9e1429c8f6f147312
parent5d9d8f3799f2f65ebaa7b485fd6078ce5c79818c (diff)
parent766f81657536fd629dc02dc34c489209c6db2a2e (diff)
downloadjson-415953c54c760212844af511515708b676fec866.tar.gz
Merge pull request #483 from notEthan/unicode_mixed
bugfix json/pure mixing escaped with literal unicode raises Encoding::CompatibilityError
-rw-r--r--lib/json/pure/parser.rb2
-rw-r--r--tests/json_parser_test.rb4
2 files changed, 5 insertions, 1 deletions
diff --git a/lib/json/pure/parser.rb b/lib/json/pure/parser.rb
index e1d701b..be48c60 100644
--- a/lib/json/pure/parser.rb
+++ b/lib/json/pure/parser.rb
@@ -179,7 +179,7 @@ module JSON
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 00b254f..146ff7c 100644
--- a/tests/json_parser_test.rb
+++ b/tests/json_parser_test.rb
@@ -115,6 +115,10 @@ class JSONParserTest < Test::Unit::TestCase
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" => {} }]