Skip to content

Commit

Permalink
Fixed infinite loop with CR #339
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbt committed Jan 12, 2015
1 parent 01c805c commit 811c86f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions History.rdoc
@@ -1,3 +1,8 @@
=== 4.2.1

* Bug fixes
* Fixed infinite loop with CR #339

=== 4.2.0 / 2014-12-06

* Major enhancements
Expand Down
4 changes: 2 additions & 2 deletions lib/rdoc/text.rb
Expand Up @@ -68,11 +68,11 @@ def expand_tabs text
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
Expand Down
3 changes: 3 additions & 0 deletions test/test_rdoc_text.rb
Expand Up @@ -56,6 +56,9 @@ def test_expand_tabs

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
Expand Down

0 comments on commit 811c86f

Please sign in to comment.