diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-10-28 21:39:36 +0200 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-10-28 21:39:36 +0200 |
commit | 5ed10e53bc783567f859eb41052dad29d419b7a0 (patch) | |
tree | e13e053368e6093baa017a78554a84504eda5345 /Lib/textwrap.py | |
parent | c6b8f0105afa4a62a382d132f03aae1b3564e93d (diff) | |
download | cpython-5ed10e53bc783567f859eb41052dad29d419b7a0.tar.gz |
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 58867f93bb..1759b0d7cf 100644 --- a/Lib/textwrap.py +++ b/Lib/textwrap.py @@ -429,11 +429,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: |