[ruby/json] Respect Coder depth when generating

https://github.com/ruby/json/commit/9c36681b17
This commit is contained in:
Étienne Barrié 2025-11-24 17:41:33 +01:00 committed by git
parent 78aa8d5b1d
commit 2f192c73cc
2 changed files with 2 additions and 2 deletions

View File

@ -1549,7 +1549,7 @@ static VALUE cState_generate_new(int argc, VALUE *argv, VALUE self)
.buffer = &buffer,
.vstate = Qfalse,
.state = state,
.depth = 0,
.depth = state->depth,
.obj = obj,
.func = generate_json
};

View File

@ -134,7 +134,7 @@ class JSONCoderTest < Test::Unit::TestCase
def test_depth
coder = JSON::Coder.new(object_nl: "\n", array_nl: "\n", space: " ", indent: " ", depth: 1)
assert_equal %({\n "foo": 42\n}), coder.dump(foo: 42)
assert_equal %({\n "foo": 42\n }), coder.dump(foo: 42)
end
def test_nesting_recovery