diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-10-28 19:43:12 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-10-28 19:43:12 (GMT) |
commit | f8152c67f52874cd4aa63f1cb3e1216382f98057 (patch) | |
tree | 40df18ddb09e88f3a17b771bc8adaecf2ecb2ec7 /Lib/textwrap.py | |
parent | 44b1020c121aa5511e8994496ee4e7a2ad9deb8d (diff) | |
parent | ea4cb63e68d96697ff8eb9ea86da6158f27b95a2 (diff) | |
download | cpython-f8152c67f52874cd4aa63f1cb3e1216382f98057.zip cpython-f8152c67f52874cd4aa63f1cb3e1216382f98057.tar.gz cpython-f8152c67f52874cd4aa63f1cb3e1216382f98057.tar.bz2 |
Issue #21827: Fixed textwrap.dedent() for the case when largest common
whitespace is a substring of smallest leading whitespace.
Based on patch by Robert Li.
Diffstat (limited to 'Lib/textwrap.py')
-rw-r--r-- | Lib/textwrap.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Lib/textwrap.py b/Lib/textwrap.py index 3ad3e18..05e0306 100644 --- a/Lib/textwrap.py +++ b/Lib/textwrap.py @@ -444,11 +444,15 @@ def dedent(text): elif margin.startswith(indent): margin = indent - # Current line and previous winner have no common whitespace: - # there is no margin. + # Find the largest common whitespace between current line and previous + # winner. else: - margin = "" - break + for i, (x, y) in enumerate(zip(margin, indent)): + if x != y: + margin = margin[:i] + break + else: + margin = margin[:len(indent)] # sanity check (testing/debugging only) if 0 and margin: |