summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-01-19 19:48:19 (GMT)
committerGeorg Brandl <georg@python.org>2008-01-19 19:48:19 (GMT)
commitc6fde7293e57f16affb068f60b1998114e041b91 (patch)
tree835ad7597ca28e21ddcb1389ec601350e912a3cb /Lib
parent14404b68d8c5a501a2f5ee6f45494865b7b38276 (diff)
downloadcpython-c6fde7293e57f16affb068f60b1998114e041b91.zip
cpython-c6fde7293e57f16affb068f60b1998114e041b91.tar.gz
cpython-c6fde7293e57f16affb068f60b1998114e041b91.tar.bz2
Fix #1146: TextWrap vs words 1-character shorter than the width.
Patch by Quentin Gallet-Gilles.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_textwrap.py13
-rw-r--r--Lib/textwrap.py7
2 files changed, 19 insertions, 1 deletions
diff --git a/Lib/test/test_textwrap.py b/Lib/test/test_textwrap.py
index 5f0b51b..787153e 100644
--- a/Lib/test/test_textwrap.py
+++ b/Lib/test/test_textwrap.py
@@ -398,6 +398,19 @@ How *do* you spell that odd word, anyways?
' 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
diff --git a/Lib/textwrap.py b/Lib/textwrap.py
index e49644d..473b98a 100644
--- a/Lib/textwrap.py
+++ b/Lib/textwrap.py
@@ -173,7 +173,12 @@ class TextWrapper:
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 width < 1:
+ space_left = 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.