385 Commits
Author SHA1 Message Date
Sebastian Turner 63ae538ecf [ruby/json] Fix ParserError#json_path with symbolize_names: true
Signed-off-by: Sebastian Turner <sebastiant3484@gmail.com>

https://github.com/ruby/json/commit/c839870678
2026-10-19 16:25:24 +00:00
Jean Boussier ad29ad7ad8 [ruby/json] Handle invalid encoding in JSON path keys
https://github.com/ruby/json/commit/e19f7d75a6
2026-10-12 14:55:31 +00:00
Jean Boussier c5597ac4bd [ruby/json] Fix parsing of number with out of range negative exponents
https://github.com/ruby/json/commit/6ea62016fb
2026-10-12 14:22:32 +00:00
Jean Boussier 817023b888 [ruby/json] Fix parsing of unescaped NULL bytes in strings
https://github.com/ruby/json/commit/1b67eb3db2
2026-10-12 13:57:23 +00:00
Jean Boussier 90e7ab3ade [ruby/json] ResumableParser: fix handling of incomplete unicode escape
`spe` is the string end, so if the escape is incomplete, it doesn't
mean we reached the end of stream, hence it's a syntax error, not
an EOS error.

https://github.com/ruby/json/commit/c1a4372837
2026-10-12 13:51:08 +00:00
Jean Boussier 0e01c2a87f [ruby/json] More hardening against adversarial encode methods
https://github.com/ruby/json/commit/429c109458
2026-10-12 08:15:47 +00:00
ydah dbd87dcc28 [ruby/json] Sort RFC 8785 keys after as_json conversion
https://github.com/ruby/json/commit/88b358d8b2
2026-10-12 07:15:16 +00:00
Jean Boussier 870969b201 [ruby/json] Better defend against to_s or encode not returning a T_STRING
https://github.com/ruby/json/commit/cdcfdb8066
2026-10-08 18:50:44 +00:00
ydah 95db6abe45 [ruby/json] Reject incompatible RFC 8785 generation options
https://github.com/ruby/json/commit/49e8df0e16
2026-10-08 09:57:55 +00:00
ydah 87c567e721 [ruby/json] Canonicalize integers as doubles in RFC 8785 mode
https://github.com/ruby/json/commit/3d9d6dd32d
2026-10-08 07:05:47 +00:00
ydah 432e0dc577 [ruby/json] Sort RFC 8785 object properties by their keys
https://github.com/ruby/json/commit/808577ae1d
2026-10-07 14:36:31 +00:00
ydah 1ebc88b530 [ruby/json] Preserve float precision in RFC 8785 number formatting
https://github.com/ruby/json/commit/193df55852
2026-10-07 13:03:24 +00:00
ydah 9d5345460e [ruby/json] Report the attempted depth in generator nesting errors
https://github.com/ruby/json/commit/37a48ef6b8
2026-10-06 13:01:32 +00:00
ydah a51a35c506 [ruby/json] Reject non-ASCII BINARY strings during JSON generation
https://github.com/ruby/json/commit/8bab92d63b
2026-10-06 12:09:48 +00:00
ydah 2c1e694a53 [ruby/json] Exclude custom instance variables from State#to_h
https://github.com/ruby/json/commit/08e72297b2
2026-10-05 15:26:55 +00:00
ydah 156c095332 [ruby/json] Honor as_json and reject disabled strict mode in JSON::Coder
https://github.com/ruby/json/commit/b63b4f1506
2026-10-05 13:45:41 +00:00
Nobuyoshi Nakada 528835f350 [ruby/json] Open gzip in binary mode
It is binary format, read in text mode stops at 0x1a (^Z).

https://github.com/ruby/json/commit/42cc52a89c
2026-10-05 13:44:03 +00:00
Jean Boussier 6930c20b65 [ruby/json] Implement rfc8785
Fix: https://github.com/ruby/json/issues/1038

Directly lift https://github.com/dryruby/json-canonicalization

At least for now, implementing most of the logic in Ruby make it
shareable between the 3 generator implementations, largely reducing
the maintenance cost.

I don't particularly expect canonicalization to be a hotspot,
but if it happens to be, I'd be open to specialize the implementation,
within reason, at least in the C generator.

https://github.com/ruby/json/commit/f103c8953f
2026-10-02 14:45:31 +00:00
ydah 8cf3b6691f [ruby/json] Fix parser error positions for newlines and multibyte characters
https://github.com/ruby/json/commit/590dd5448d
2026-10-02 13:03:45 +00:00
ydah a349827f06 [ruby/json] Preserve complete UTF-8 characters in parse error snippets
https://github.com/ruby/json/commit/c484f8fa82
2026-10-02 12:21:27 +00:00
Nobuyoshi Nakada 1c03c515fa [ruby/json] Fix tempfile leak
The `tempfile` variable refers to different things in the first half
and the second half.

https://github.com/ruby/json/commit/0edc03a14e
2026-10-01 11:14:08 +00:00
ydah ad5851e797 [ruby/json] Prevent use-after-free when strings change during IO generation
https://github.com/ruby/json/commit/f720614728
2026-10-01 06:31:16 +00:00
ydah f452e5403e [ruby/json] Prevent ResumableParser from stalling on invalid object keys
https://github.com/ruby/json/commit/452f31b569
2026-10-01 06:21:36 +00:00
ydah 4f9ec01a51 [ruby/json] Prevent crashes with non-Proc on_load callbacks
Convert non-Proc on_load callbacks through to_proc and validate the result in the shared parser configuration. Previously, arbitrary values were stored and passed directly to rb_proc_call_with_block.

Cover Method callbacks in JSON.parse, JSON::Coder, and ResumableParser, along with invalid types, invalid conversion results, and nil or false callbacks.

https://github.com/ruby/json/commit/672da19fd5
2026-09-30 15:42:28 +00:00
Lucas Dohmen 7da1b1c7a0 [ruby/json] Fix Interoperability with Zlib::GzipReader
GzipReader offers both a read and to_io method. The read method returns
the uncompressed file as a string. The to_io method returns the
compressed file. The JSON.load method first tests for the to_io method
and uses it before testing for the read method. This results in reading
the compressed file, which is invalid JSON.

Instead, we now test for the read method first.

https://github.com/ruby/json/commit/b6a5d35245
2026-09-30 13:46:09 +00:00
ydah 9d7551d8c2 [ruby/json] Prevent crashes with non-Proc as_json callbacks
Convert non-Proc callbacks through to_proc and validate the result in both configuration and the as_json setter. rb_convert_type accepts unrelated T_DATA objects without conversion, allowing them to reach Proc APIs and crash.

Cover Method callbacks, invalid callback types, and to_proc returning a non-Proc object.

https://github.com/ruby/json/commit/f5c889de9c
2026-09-30 13:42:11 +00:00
youdie006 16d68e7f1f [ruby/json] JRuby: keep the whole character after an invalid escape
With allow_invalid_escape, the JRuby decoder appended the code point read
after a stray backslash with append(int), which writes only its low byte.
"\\é" became "\xE9" and "\\あ" became "B", where the C extension
keeps the character. Use writeUtf8Char, as the other code point paths do.

https://github.com/ruby/json/commit/edb3b20d6d
2026-09-29 07:10:44 +00:00
Jean Boussier 5fe7d61b20 [ruby/json] Ensure default_sort_keys_proc isn't reassigned.
It's assignable from Ruby simply for the gem's own initialization,
but it should never be re-assigned later.

Fix: https://github.com/ruby/json/pull/1079

https://github.com/ruby/json/commit/cc32ef5cf5
2026-09-28 18:59:04 +02:00
Matt Valentine-House 43b1e17d08 json: reject non-shareable default sort_keys proc from non-main Ractors
JSON::State.default_sort_keys_proc is registered at extension load time
so it's owned by the main Ractor.

When we implement the registration table on each Ractor storing another
Ractor's unshareable Proc into that slot leaves a dangling reference
when the owning Ractor runs a local GC.

This commit ensures that we won't use a shareable proc by raising a
Ractor::IsolationError.
2026-09-25 19:24:10 +01:00
Ojus Chugh c402c18fe5 [ruby/json] Add error position and json_path to the JRuby extension
https://github.com/ruby/json/commit/522b015063
2026-09-16 13:03:13 +00:00
youdie006 20b5bdbaa7 [ruby/json] Make GeneratorState#_configure only write the options it is given
The C extension walks the given hash and writes only the keys present
(generator.c:1860), and since #1076 the pure generator does the same.
The Java one re-wrote every option with its class default, so any
configure or merge silently reset max_nesting, allow_nan, ascii_only,
script_safe, strict, buffer_initial_length, allow_duplicate_key,
as_json and sort_keys.

Re-enables the two tests #1076 marked pending on JRuby.

https://github.com/ruby/json/commit/bbc73fb69d
2026-09-11 12:54:26 +00:00
youdie006 a4b95bdd7e [ruby/json] Make State#configure and #merge only write the options they are given
The pure-Ruby generator's private _configure gives every keyword a literal
default, so a call that passes one option silently resets the other fifteen.
The method is also aliased as merge, so a state built with indent/object_nl
starts emitting compact JSON after any later configure call.

The C extension does not behave this way. configure_state_i walks only the
keys actually present in the hash, so State#merge really merges there.
Default the keywords to the current ivars so the pure generator agrees.

initialize already assigns every ivar to its literal default before calling
_configure(**opts), so construction is unchanged.

https://github.com/ruby/json/commit/46fbe24b04
2026-09-09 20:21:40 +00:00
Koichi ITO 847c5ce1ac [ruby/json] Fix JSON.load_file and JSON.load_file! to load on Ruby 2.7.0 through 2.7.2
Since https://github.com/ruby/json/commit/ebf0f29, `load_file` and `load_file!` forward their arguments to
`parse` and `parse!` with `...` after a leading parameter. Ruby 2.7 accepts `...` only on its own;
a leading parameter before it was added in Ruby 3.0 and reached the 2.7 series in 2.7.3, so on Ruby 2.7.0
through 2.7.2 requiring json 3.0 raises a `SyntaxError` at `lib/json/common.rb`, while the gemspec still allows
Ruby 2.7 as a whole.

`parse` and `parse!` take keyword arguments only, so forwarding `**options` passes exactly what `...` passed,
on every Ruby the gem supports.

A `method_missing` helper in the parser tests used the same form; it takes an anonymous splat now,
so the test suite itself loads on those versions.

Checked with `ruby -c` on Ruby 2.7.0, 2.7.2, 2.7.3, and 3.0.7, and with the test suite on Ruby 2.7.2 and 3.0.7.

https://github.com/ruby/json/commit/29dad14674
2026-09-08 10:42:56 +00:00
Jean Boussier f60a60427f [ruby/json] Centralize requires in the test suite
https://github.com/ruby/json/commit/73edd53644
2026-09-08 08:23:12 +00:00
Jean Boussier d98d7978dc [ruby/json] Restore the limit positional argument of JSON.dump
I really wanted to get rid of this because the argument parsing is
awful and costly.

But `rdoc` has been using this positional argument for decades,
and while the fix has been merged, having to upgrade to the latest
rdoc is a bit too disruptive.

https://github.com/ruby/json/commit/566bd7c108
2026-09-08 07:06:44 +00:00
Elankumaran Srinivasan 4219a1aa68 [ruby/json] Fix parser silently accepting a lone trailing surrogate in string values
The C parser guards leading-first surrogate pairs but silently accepts
a lone trailing surrogate, encoding U+DC00..U+DFFF as three UTF-8 bytes
into the output buffer. The returned Ruby String is tagged UTF-8 but
fails valid_encoding? and raises misleading errors from downstream
String operations (upcase, split, regex, encode, JSON.generate).

Add a symmetric branch alongside the leading-surrogate check to raise
JSON::ParserError at the parse boundary. Extend test_invalid_surogates
with the new cases and move the three JSONTestSuite fixtures that this
fix newly rejects from INVALID_ENCODING_TESTS into UNDEFINED_FAILING,
closing the CRuby/JRuby parser parity gap documented in the file.

https://github.com/ruby/json/commit/82bf6bedcf
2026-09-07 06:53:10 +00:00
Shizuo FujitaandClaude Opus 5 5985f8bb18 [ruby/json] Fix SEGV when as_json returns a non-String for an invalid symbol
In strict mode, a Symbol whose name is not UTF-8 compatible was passed to
generate_json_string, which handed the as_json result to
raw_generate_json_string without checking its type. A non-String result was
then read as a String, segfaulting the process.

Route strict symbols through the T_STRING case of generate_json_general so
they reuse its as_json handling. That re-dispatches the result by type, and
its as_json_called flag stops a symbol returned by as_json from recursing.

https://github.com/ruby/json/commit/2d73e6bdfe

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-03 07:35:48 +00:00
Ojus ChughandJean Boussier 065a5592d2 [ruby/json] Add JSON::ParserError#json_path
(https://github.com/ruby/json/pull/1062)

Add JSON::ParserError#json_path

https://github.com/ruby/json/commit/9ae76bdd3d

Co-authored-by: Jean Boussier <byroot@ruby-lang.org>
2026-08-24 15:04:10 +00:00
Jean Boussier b13b6b748b [ruby/json] Update Hash syntax in tests
https://github.com/ruby/json/commit/0479b66aec
2026-08-17 07:07:20 +00:00
Jean Boussier 284566bf6b [ruby/json] Add Ractor compatibility tests for JSON.load and JSON.dump
https://github.com/ruby/json/commit/4ddc092392
2026-08-11 08:12:51 +00:00
Jean Boussier ac60d4ae4d [ruby/json] Make generator options strict
https://github.com/ruby/json/commit/a8d7f6da6b
2026-08-11 08:12:51 +00:00
Jean Boussier e79dd68040 [ruby/json] Make parsing options keyword arguments
Or at least behave like them.

https://github.com/ruby/json/commit/ebf0f2901c
2026-08-11 08:12:50 +00:00
Jean Boussier 86d92b7fed [ruby/json] Remove the limit positional argument of JSON.dump.
It's entirely redundant with `max_nesting`, makes little sense
except to match Marshal signature exactly, but I don't see the
point.

https://github.com/ruby/json/commit/6e668d2cfe
2026-08-11 08:12:50 +00:00
Jean Boussier b816355e45 [ruby/json] Remove escape_slash
https://github.com/ruby/json/commit/2aa6ecb44f
2026-08-11 08:12:50 +00:00
Jean Boussier aac310d257 [ruby/json] Remove JSON::GenericObject
https://github.com/ruby/json/commit/273b38d8f4
2026-08-11 08:12:50 +00:00
Jean Boussier 92fee2a3f5 [ruby/json] Remove JSON.fast_generate
https://github.com/ruby/json/commit/e93e5d645e
2026-08-11 08:12:50 +00:00
Jean Boussier 87dbb3821d [ruby/json] Remove create_additions option
https://github.com/ruby/json/commit/1f65fe1c2d
2026-08-11 08:12:50 +00:00
Jean Boussier f61922fda3 [ruby/json] Remove JSON::State#[] and JSON::State#[]=
https://github.com/ruby/json/commit/c1d784113c
2026-08-11 08:12:49 +00:00
Jean Boussier e8fbcef28e [ruby/json] Remove default_options singleton accessors
https://github.com/ruby/json/commit/e8f34a8f2d
2026-08-11 08:12:49 +00:00
Jean Boussier 8bf14d3a70 [ruby/json] Make allow_comments: false the default
https://github.com/ruby/json/commit/bc24969dab
2026-08-11 08:12:49 +00:00