summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--ext/json/generator/generator.c2
-rwxr-xr-xtest/json/test_json_generate.rb10
3 files changed, 17 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 0f2ba38..98c376d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Wed Feb 11 11:01:33 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * ext/json/generator/generator.c (generate_json): get rid of
+ unnecessary recursive calls which can cause infinite recursion.
+ T_STRING may not have rb_cString.
+
Wed Feb 11 07:53:35 2015 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* test/win32ole/test_word.rb: use skip method to skip test.
diff --git a/ext/json/generator/generator.c b/ext/json/generator/generator.c
index 7805cde..9641ecb 100644
--- a/ext/json/generator/generator.c
+++ b/ext/json/generator/generator.c
@@ -880,7 +880,7 @@ static void generate_json(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *s
} else {
tmp = rb_funcall(obj, i_to_s, 0);
Check_Type(tmp, T_STRING);
- generate_json(buffer, Vstate, state, tmp);
+ generate_json_string(buffer, Vstate, state, tmp);
}
}
diff --git a/test/json/test_json_generate.rb b/test/json/test_json_generate.rb
index 8db0b78..1834290 100755
--- a/test/json/test_json_generate.rb
+++ b/test/json/test_json_generate.rb
@@ -334,4 +334,14 @@ EOT
assert_equal true, JSON.generate(["\xea"])
end
end
+
+ def test_string_subclass
+ s = Class.new(String) do
+ def to_s; self; end
+ undef to_json
+ end
+ assert_nothing_raised(SystemStackError) do
+ assert_equal '[""]', JSON.generate([s.new])
+ end
+ end
end