Skip to content

Commit

Permalink
Merge pull request #483 from notEthan/unicode_mixed
Browse files Browse the repository at this point in the history
bugfix json/pure mixing escaped with literal unicode raises Encoding::CompatibilityError
  • Loading branch information
hsbt committed Jun 13, 2022
2 parents 5d9d8f3 + 766f816 commit 415953c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/json/pure/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions tests/json_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" => {} }]
Expand Down

0 comments on commit 415953c

Please sign in to comment.