Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encode \uXXXX unescapes as ASCII_8BIT #484

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 2 additions & 0 deletions tests/json_encoding_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down