Skip to content

JSON::Parser issues with encodings #4281

@headius

Description

@headius

Environment

JRuby master running updated Ruby 2.3.x tests.

Expected Behavior

The following tests were added with a large update of json tests:

  def test_argument_encoding
    source = "{}".force_encoding("ascii-8bit")
    JSON::Parser.new(source)
    assert_equal Encoding::ASCII_8BIT, source.encoding
  end if defined?(Encoding::ASCII_8BIT)

  def test_error_message_encoding
    bug10705 = '[ruby-core:67386] [Bug #10705]'
    json = "\"\xE2\x88\x9A\"".force_encoding(Encoding::UTF_8)
    e = assert_raise(JSON::ParserError) {
      JSON.parse(json)
    }
    assert_equal(Encoding::UTF_8, e.message.encoding, bug10705)
    assert_include(e.message, json, bug10705)
  end if defined?(Encoding::UTF_8)
...

Actual Behavior

They fail. In the first case, the encoding of the source appears to change to UTF-8. The second does not raise an error for improperly-encoded content.

  5) Failure:
TestJSON#test_argument_encoding [/Users/headius/projects/jruby/test/mri/json/test_json.rb:552]:
<#<Encoding:ASCII-8BIT>> expected but was
<#<Encoding:UTF-8>>.

  6) Failure:
TestJSON#test_error_message_encoding [/Users/headius/projects/jruby/test/mri/json/test_json.rb:558]:
JSON::ParserError expected but nothing was raised.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions