]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
SF bug 797650: Infinite loop in textwrap.py
authorRaymond Hettinger <python@rcn.com>
Sat, 30 Aug 2003 14:52:35 +0000 (14:52 +0000)
committerRaymond Hettinger <python@rcn.com>
Sat, 30 Aug 2003 14:52:35 +0000 (14:52 +0000)
When the indents were set to longer than the width and long word breaking
was enabled, an infinite loop would result because the inner loop did not
assure that at least one character was stripped off on every pass.

Lib/test/test_textwrap.py
Lib/textwrap.py
Misc/NEWS

index 904c79091dd7b44e38d2e7e27260960d7feb58d1..a0111680b42923576aa1745554bf36bad5333297 100644 (file)
@@ -305,6 +305,16 @@ How *do* you spell that odd word, anyways?
                         ['Did you say "supercalifragilisticexpialidocious?"',
                          'How *do* you spell that odd word, anyways?'])
 
+        # SF bug 797650.  Prevent an infinite loop by making sure that at
+        # least one character gets split off on every pass.
+        self.check_wrap('-'*10+'hello', 10,
+                        ['----------',
+                         '               h',
+                         '               e',
+                         '               l',
+                         '               l',
+                         '               o'],
+                        subsequent_indent = ' '*15)
 
     def test_nobreak_long(self):
         # Test with break_long_words disabled
index a4a549848f3dee6de3458497b0e9cc07a8cfa157..f371fbbe5ac7d8221277226969a0d61ca66eaadd 100644 (file)
@@ -168,7 +168,7 @@ class TextWrapper:
         Handle a chunk of text (most likely a word, not whitespace) that
         is too long to fit in any line.
         """
-        space_left = width - cur_len
+        space_left = max(width - cur_len, 1)
 
         # If we're allowed to break long words, then do so: put as much
         # of the next chunk onto the current line as will fit.
index 2af1ef9e501f42ef5820ec4235bca7c8b04dd696..b682c27af227f5fbaeba73b4732ca4d0ed025cfb 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -33,6 +33,9 @@ Extension modules
 Library
 -------
 
+- Bug #797650:  textwrap.py now avoids an infinite loop when one of the
+  indent arguments is set longer than the total width.
+
 - Bug #796149: time.strptime() now handles having parentheses in the
   format string properly.