summaryrefslogtreecommitdiff
path: root/test/json/json_generator_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/json/json_generator_test.rb')
-rw-r--r--test/json/json_generator_test.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/json/json_generator_test.rb b/test/json/json_generator_test.rb
index d7f9ebeb68..3d9ab7a364 100644
--- a/test/json/json_generator_test.rb
+++ b/test/json/json_generator_test.rb
@@ -40,6 +40,43 @@ class JSONGeneratorTest < Test::Unit::TestCase
EOT
end
+ def silence
+ v = $VERBOSE
+ $VERBOSE = nil
+ yield
+ ensure
+ $VERBOSE = v
+ end
+
+ def test_remove_const_segv
+ stress = GC.stress
+ const = JSON::SAFE_STATE_PROTOTYPE.dup
+
+ bignum_too_long_to_embed_as_string = 1234567890123456789012345
+ expect = bignum_too_long_to_embed_as_string.to_s
+ GC.stress = true
+
+ 10.times do |i|
+ tmp = bignum_too_long_to_embed_as_string.to_json
+ raise "'\#{expect}' is expected, but '\#{tmp}'" unless tmp == expect
+ end
+
+ silence do
+ JSON.const_set :SAFE_STATE_PROTOTYPE, nil
+ end
+
+ 10.times do |i|
+ assert_raise TypeError do
+ bignum_too_long_to_embed_as_string.to_json
+ end
+ end
+ ensure
+ GC.stress = stress
+ silence do
+ JSON.const_set :SAFE_STATE_PROTOTYPE, const
+ end
+ end
+
def test_generate
json = generate(@hash)
assert_equal(parse(@json2), parse(json))