Skip to content

Commit 0a4f320

Browse files
committed
Respect Coder depth when generating
1 parent 81f9b33 commit 0a4f320

File tree

4 files changed

+2
-12
lines changed

4 files changed

+2
-12
lines changed

ext/json/ext/generator/generator.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1549,7 +1549,7 @@ static VALUE cState_generate_new(int argc, VALUE *argv, VALUE self)
15491549
.buffer = &buffer,
15501550
.vstate = Qfalse,
15511551
.state = state,
1552-
.depth = 0,
1552+
.depth = state->depth,
15531553
.obj = obj,
15541554
.func = generate_json
15551555
};

java/src/json/ext/GeneratorState.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,12 @@ public IRubyObject generate(ThreadContext context, IRubyObject obj) {
259259
@JRubyMethod
260260
public IRubyObject generate_new(ThreadContext context, IRubyObject obj, IRubyObject io) {
261261
GeneratorState newState = (GeneratorState)dup();
262-
newState.resetDepth();
263262
return newState.generate(context, obj, io);
264263
}
265264

266265
@JRubyMethod
267266
public IRubyObject generate_new(ThreadContext context, IRubyObject obj) {
268267
GeneratorState newState = (GeneratorState)dup();
269-
newState.resetDepth();
270268
return newState.generate(context, obj, context.nil);
271269
}
272270

@@ -504,10 +502,6 @@ public IRubyObject depth_set(IRubyObject vDepth) {
504502
return vDepth;
505503
}
506504

507-
public void resetDepth() {
508-
depth = 0;
509-
}
510-
511505
private ByteList prepareByteList(ThreadContext context, IRubyObject value) {
512506
RubyString str = value.convertToString();
513507
if (str.getEncoding() != UTF8Encoding.INSTANCE) {

lib/json/truffle_ruby/generator.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,6 @@ def generate_new(obj, anIO = nil) # :nodoc:
352352
dup.generate(obj, anIO)
353353
end
354354

355-
private def initialize_copy(_orig)
356-
@depth = 0
357-
end
358-
359355
# Handles @allow_nan, @buffer_initial_length, other ivars must be the default value (see above)
360356
private def generate_json(obj, buf)
361357
case obj

test/json/json_coder_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def test_json_coder_string_invalid_encoding
134134

135135
def test_depth
136136
coder = JSON::Coder.new(object_nl: "\n", array_nl: "\n", space: " ", indent: " ", depth: 1)
137-
assert_equal %({\n "foo": 42\n}), coder.dump(foo: 42)
137+
assert_equal %({\n "foo": 42\n }), coder.dump(foo: 42)
138138
end
139139

140140
def test_nesting_recovery

0 commit comments

Comments
 (0)