ruby-changes:37481
From: nobu <ko1@a...>
Date: Wed, 11 Feb 2015 11:01:42 +0900 (JST)
Subject: [ruby-changes:37481] nobu:r49562 (trunk): generator.c: fix infinite recursion
nobu 2015-02-11 11:01:36 +0900 (Wed, 11 Feb 2015) New Revision: 49562 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49562 Log: generator.c: fix infinite recursion * 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. Modified files: trunk/ChangeLog trunk/ext/json/generator/generator.c trunk/test/json/test_json_generate.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 49561) +++ ChangeLog (revision 49562) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Feb 11 11:01:33 2015 Nobuyoshi Nakada <nobu@r...> + + * 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@n...> * test/win32ole/test_word.rb: use skip method to skip test. Index: ext/json/generator/generator.c =================================================================== --- ext/json/generator/generator.c (revision 49561) +++ ext/json/generator/generator.c (revision 49562) @@ -880,7 +880,7 @@ static void generate_json(FBuffer *buffe https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.c#L880 } 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); } } Index: test/json/test_json_generate.rb =================================================================== --- test/json/test_json_generate.rb (revision 49561) +++ test/json/test_json_generate.rb (revision 49562) @@ -334,4 +334,14 @@ EOT https://github.com/ruby/ruby/blob/trunk/test/json/test_json_generate.rb#L334 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/