Quentin Gallet-Gilles added the comment:

The bug is present in trunk and has been there since rev 33955. This
revision contained a fix to an infinite loop when indentation was set
longer than width with long word breaking enabled. In that case, it
would strip off at least one character on every pass. The fix was
however a bit too general, leading to the reported bug.

The added patch makes sure this doesn't happen anymore when indentation
isn't involved.

----------
nosy: +quentin.gallet-gilles

__________________________________
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1146>
__________________________________
Index: Lib/textwrap.py
===================================================================
--- Lib/textwrap.py	(revision 58153)
+++ Lib/textwrap.py	(working copy)
@@ -173,7 +173,12 @@
         Handle a chunk of text (most likely a word, not whitespace) that
         is too long to fit in any line.
         """
-        space_left = max(width - cur_len, 1)
+        # Figure out when indent is larger than the specified width, and make
+        # sure at least one character is stripped off on every pass
+        if self.width > width:
+            space_left = max(width - cur_len, 1)
+        else:
+            space_left = width - cur_len
 
         # 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: Lib/test/test_textwrap.py
===================================================================
--- Lib/test/test_textwrap.py	(revision 58153)
+++ Lib/test/test_textwrap.py	(working copy)
@@ -398,6 +398,19 @@
                          '               o'],
                         subsequent_indent = ' '*15)
 
+        # bug 1146.  Prevent a long word to be wrongly wrapped when the
+        # preceding word is exactly one character shorter than the width
+        self.check_wrap(self.text, 12,
+                        ['Did you say ',
+                         '"supercalifr',
+                         'agilisticexp',
+                         'ialidocious?',
+                         '" How *do*',
+                         'you spell',
+                         'that odd',
+                         'word,',
+                         'anyways?'])
+
     def test_nobreak_long(self):
         # Test with break_long_words disabled
         self.wrapper.break_long_words = 0
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to