summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Frank <flori@ping.de>2010-08-07 11:09:56 +0200
committerFlorian Frank <flori@ping.de>2010-08-07 11:09:56 +0200
commitde9c610ef06af24e2dc2389892fb00e21be9202d (patch)
treeb68927409bd71f25c2e4dabd44b900fd8e09613a
parentbec5586cd5318e722fd599263105fa56b0bbe3e1 (diff)
downloadjson-de9c610ef06af24e2dc2389892fb00e21be9202d.tar.gz
do not forget to dup the state
-rw-r--r--ext/json/ext/generator/generator.c5
-rwxr-xr-xtests/test_json_generate.rb8
2 files changed, 11 insertions, 2 deletions
diff --git a/ext/json/ext/generator/generator.c b/ext/json/ext/generator/generator.c
index b4cb740..0617466 100644
--- a/ext/json/ext/generator/generator.c
+++ b/ext/json/ext/generator/generator.c
@@ -14,7 +14,7 @@ static VALUE mJSON, mExt, mGenerator, cState, mGeneratorMethods, mObject,
static ID i_to_s, i_to_json, i_new, i_indent, i_space, i_space_before,
i_object_nl, i_array_nl, i_max_nesting, i_allow_nan, i_ascii_only,
i_pack, i_unpack, i_create_id, i_extend, i_key_p, i_aref, i_send,
- i_respond_to_p, i_match, i_keys, i_depth;
+ i_respond_to_p, i_match, i_keys, i_depth, i_dup;
/*
* Copyright 2001-2004 Unicode, Inc.
@@ -1043,7 +1043,7 @@ static VALUE cState_from_state_s(VALUE self, VALUE opts)
if (NIL_P(CJSON_SAFE_STATE_PROTOTYPE)) {
CJSON_SAFE_STATE_PROTOTYPE = rb_const_get(mJSON, i_SAFE_STATE_PROTOTYPE);
}
- return CJSON_SAFE_STATE_PROTOTYPE;
+ return rb_funcall(CJSON_SAFE_STATE_PROTOTYPE, i_dup, 0);
}
}
@@ -1406,6 +1406,7 @@ void Init_generator()
i_respond_to_p = rb_intern("respond_to?");
i_match = rb_intern("match");
i_keys = rb_intern("keys");
+ i_dup = rb_intern("dup");
#ifdef HAVE_RUBY_ENCODING_H
CEncoding_UTF_8 = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-8"));
i_encoding = rb_intern("encoding");
diff --git a/tests/test_json_generate.rb b/tests/test_json_generate.rb
index 8dc804b..b2c1271 100755
--- a/tests/test_json_generate.rb
+++ b/tests/test_json_generate.rb
@@ -164,4 +164,12 @@ EOT
assert_raises(GeneratorError) { pretty_generate([JSON::MinusInfinity]) }
assert_equal "[\n -Infinity\n]", pretty_generate([JSON::MinusInfinity], :allow_nan => true)
end
+
+ def test_depth
+ ary = []; ary << ary
+ s = JSON.state.new
+ assert_equal 0, s.depth
+ assert_raises(JSON::NestingError) { JSON(ary, s) }
+ #assert_equal 20, s.depth
+ end
end