ruby-changes:37142
From: nobu <ko1@a...>
Date: Mon, 12 Jan 2015 18:01:37 +0900 (JST)
Subject: [ruby-changes:37142] nobu:r49223 (trunk): rdoc/text.rb: fix infinite loop
nobu 2015-01-12 18:01:28 +0900 (Mon, 12 Jan 2015) New Revision: 49223 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49223 Log: rdoc/text.rb: fix infinite loop * lib/rdoc/text.rb (expand_tabs): get rid of infinite loop with CR. should check if substitution occurred too. [ruby-dev:48813] [Bug #10732] Modified files: trunk/ChangeLog trunk/lib/rdoc/text.rb trunk/test/rdoc/test_rdoc_text.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 49222) +++ ChangeLog (revision 49223) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Jan 12 18:01:24 2015 Nobuyoshi Nakada <nobu@r...> + + * lib/rdoc/text.rb (expand_tabs): get rid of infinite loop with + CR. should check if substitution occurred too. + [ruby-dev:48813] [Bug #10732] + Mon Jan 12 16:45:46 2015 Seiei Higa <hanachin@g...> * vm_method.c (rb_alias): raise a NameError when creating alias to Index: lib/rdoc/text.rb =================================================================== --- lib/rdoc/text.rb (revision 49222) +++ lib/rdoc/text.rb (revision 49223) @@ -68,11 +68,11 @@ module RDoc::Text https://github.com/ruby/ruby/blob/trunk/lib/rdoc/text.rb#L68 expanded = [] text.each_line do |line| - line.gsub!(/^((?:.{8})*?)([^\t\r\n]{0,7})\t/) do + nil while line.gsub!(/(?:\G|\r)((?:.{8})*?)([^\t\r\n]{0,7})\t/) do r = "#{$1}#{$2}#{' ' * (8 - $2.size)}" r.force_encoding text.encoding if Object.const_defined? :Encoding r - end until line !~ /\t/ + end expanded << line end Index: test/rdoc/test_rdoc_text.rb =================================================================== --- test/rdoc/test_rdoc_text.rb (revision 49222) +++ test/rdoc/test_rdoc_text.rb (revision 49223) @@ -56,6 +56,9 @@ class TestRDocText < RDoc::TestCase https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_text.rb#L56 assert_equal('. .', expand_tabs(".\t\t."), 'dot tab tab dot') + + assert_equal('a a', + Timeout.timeout(1) {expand_tabs("\ra\ta")}, "carriage return") end def test_expand_tabs_encoding -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/