Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Fix `JSON::ParserError#json_path` raising `NoMethodError` when the document was parsed with `symbolize_names: true`.
* Fix `JSON.generate` not detecting duplicate keys such as `{ "1" => 1, 1 => 2 }`.
* JRuby: raise `TypeError` when a String subclass used as a Hash key has a `to_s` that doesn't return a String, like the C extension.
* JRuby: parse error messages quote the same snippet as the C extension, stopping at whitespace and never splitting a multibyte character.

### 2026-10-13 (3.1.0)

Expand Down
35 changes: 28 additions & 7 deletions java/src/json/ext/Parser.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 3 additions & 9 deletions test/json/json_ext_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,18 @@ def test_allocate

def test_error_messages
ex = assert_raise(ParserError) { parse('Infinity something') }
unless RUBY_PLATFORM =~ /java/
assert_equal "unexpected token 'Infinity' at line 1 column 1", ex.message
end
assert_equal "unexpected token 'Infinity' at line 1 column 1", ex.message

ex = assert_raise(ParserError) { parse('foo bar') }
unless RUBY_PLATFORM =~ /java/
assert_equal "unexpected token 'foo' at line 1 column 1", ex.message
end
assert_equal "unexpected token 'foo' at line 1 column 1", ex.message

ex = assert_raise(ParserError) { parse('-Infinity something') }
unless RUBY_PLATFORM =~ /java/
assert_equal "invalid number: '-Infinity' at line 1 column 1", ex.message
end

ex = assert_raise(ParserError) { parse('NaN something') }
unless RUBY_PLATFORM =~ /java/
assert_equal "unexpected token 'NaN' at line 1 column 1", ex.message
end
assert_equal "unexpected token 'NaN' at line 1 column 1", ex.message

ex = assert_raise(ParserError) { parse(' ') }
unless RUBY_PLATFORM =~ /java/
Expand Down
4 changes: 0 additions & 4 deletions test/json/json_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,6 @@ def test_parse_error_incomplete_hash
end

def test_parse_error_snippet
omit "JRuby errors don't contain positions" if RUBY_ENGINE == "jruby"

error = assert_raise(JSON::ParserError) { JSON.parse("あああああああああああああああああああああああ") }
assert_equal "unexpected character: 'ああああああああああ' at line 1 column 1", error.message

Expand Down Expand Up @@ -898,8 +896,6 @@ def test_parse_error_snippet
end

def test_parse_error_snippet_multibyte_boundaries
omit "JRuby errors don't contain positions" if RUBY_ENGINE == "jruby"

['é', '日', '😀'].each do |char|
['', ' ', "\n", "\t", "\r"].each do |suffix|
error = assert_raise(JSON::ParserError) { JSON.parse(char + suffix) }
Expand Down