Skip to content
Merged
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: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### Unreleased

* Handle invalid types passed as `max_nesting` option.

### 2026-05-28 (2.19.7)

* Fix some more edge cases with out of range floats.
Expand Down
2 changes: 1 addition & 1 deletion ext/json/ext/generator/generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -1581,7 +1581,7 @@ static VALUE cState_max_nesting(VALUE self)

static long long_config(VALUE num)
{
return RTEST(num) ? FIX2LONG(num) : 0;
return RTEST(num) ? NUM2LONG(num) : 0;
}

// depth must never be negative; reject early with a clear error.
Expand Down
3 changes: 3 additions & 0 deletions lib/json/truffle_ruby/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ def configure(opts)
if !opts.key?(:max_nesting) # defaults to 100
@max_nesting = 100
elsif opts[:max_nesting]
unless opts[:max_nesting].is_a?(Integer)
raise TypeError, ":max_nesting must be an Integer, got: #{opts[:max_nesting].class}"
end
@max_nesting = opts[:max_nesting]
else
@max_nesting = 0
Expand Down
2 changes: 2 additions & 0 deletions test/json/json_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,8 @@ def test_nesting
assert_equal too_deep, ok
ok = generate too_deep_ary, :max_nesting => 0
assert_equal too_deep, ok

assert_raise(TypeError) { generate too_deep_ary, max_nesting: "garbage" }
end

def test_backslash
Expand Down
Loading