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: 1 addition & 1 deletion ext/json/generator/generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
5 changes: 5 additions & 0 deletions test/json/json_coder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ def test_json_coder_string_invalid_encoding
assert_equal 2, calls
end

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)
end

def test_nesting_recovery
coder = JSON::Coder.new
ary = []
Expand Down