14 Commits
Author SHA1 Message Date
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
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
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
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
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
Randy Stauner 8b9661995b [ruby/json] Fix json generation for symbols on TruffleRuby
https://github.com/ruby/json/commit/0e99fcb581
2026-03-27 06:45:21 +00:00
Étienne Barrié 2f192c73cc [ruby/json] Respect Coder depth when generating
https://github.com/ruby/json/commit/9c36681b17
2025-11-27 13:01:57 +00:00
Étienne Barrié 78aa8d5b1d [ruby/json] Test current behavior regarding depth for Coder
Coder currently ignores its depth and always resets it to 0 when
generating a new JSON document.

https://github.com/ruby/json/commit/cca1f38316
2025-11-27 13:01:56 +00:00
Jean Boussier 5153a2dcb3 [ruby/json] Invoke as_json callback for strings with invalid encoding
Fix: https://github.com/ruby/json/issues/873

This allow users to encode binary strings if they so wish.
e.g. they can use Base64 or similar, or chose to replace invalid
characters with something else.

https://github.com/ruby/json/commit/b1b16c416f
2025-11-02 14:48:33 +00:00
Jean Boussier 8e8e327870 [ruby/json] Fix concurrent usage of JSON::Coder#dump
Fix: https://github.com/rails/rails/commit/90616277e3d8fc46c9cf35d6a7470ff1ea0092f7#r168784389

Because the `depth` counter is inside `JSON::State` it can't be used
concurrently, and in case of a circular reference the counter may be
left at the max value.

The depth counter should be moved outside `JSON_Generator_State` and
into `struct generate_json_data`, but it's a larger refactor.

In the meantime, `JSON::Coder` calls `State#generate_new` so I changed
that method so that it first copy the state on the stack.

https://github.com/ruby/json/commit/aefa671eca
2025-10-25 08:57:48 +00:00
Jean Boussier 1042a0bdd8 JSON::Coder callback now recieve a second argument to mark object keys
e.g.
```ruby
{ 1 => 2 }
```

The callback will be invoked for `1` as while it has a native JSON
equivalent, it's not legal as an object name.
2025-09-19 19:30:10 +09:00
Jean Boussier 0e0f0dfd07 Fix JSON::Coder to cast non-string keys. 2025-08-27 10:01:52 +09:00
Étienne BarriéandJean Boussier f865148e19 Fix JSON::Coder to call as_json proc for NaN and Infinity
Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2025-02-06 16:02:03 +09:00
Étienne BarriéandJean Boussier 89e316ad06 Introduce JSON::Coder
Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2025-01-28 15:41:47 +09:00