diff --git a/lib/json/pure/parser.rb b/lib/json/pure/parser.rb index e1d701b3..be48c607 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_encoding_test.rb b/tests/json_encoding_test.rb index cc7b7155..1a380a4a 100644 --- a/tests/json_encoding_test.rb +++ b/tests/json_encoding_test.rb @@ -8,6 +8,7 @@ class JSONEncodingTest < Test::Unit::TestCase def setup @utf_8 = '"© ≠ €!"' @ascii_8bit = @utf_8.dup.force_encoding('ascii-8bit') + @mixed = '"© \u2260 €!"' @parsed = "© ≠ €!" @generated = '"\u00a9 \u2260 \u20ac!"' if String.method_defined?(:encode) @@ -29,6 +30,7 @@ def setup def test_parse assert_equal @parsed, JSON.parse(@ascii_8bit) assert_equal @parsed, JSON.parse(@utf_8) + assert_equal @parsed, JSON.parse(@mixed) assert_equal @parsed, JSON.parse(@utf_16be) assert_equal @parsed, JSON.parse(@utf_16le) assert_equal @parsed, JSON.parse(@utf_32be)