diff -r fdfa15a9243c -r 34e88a05562f Lib/test/test_textwrap.py --- a/Lib/test/test_textwrap.py Sat Jun 21 13:59:25 2014 +0200 +++ b/Lib/test/test_textwrap.py Sun Jun 22 14:35:10 2014 -0400 @@ -732,6 +732,11 @@ expect = "hello there\n how are you?" self.assertEqual(expect, dedent(text)) + # test margin is smaller than smallest indent + text = " \thello there\n \thow are you?\n \tI'm fine, thanks" + expect = " \thello there\n \thow are you?\n\tI'm fine, thanks" + self.assertEqual(expect, dedent(text)) + # Test textwrap.indent class IndentTestCase(unittest.TestCase): diff -r fdfa15a9243c -r 34e88a05562f Lib/textwrap.py --- a/Lib/textwrap.py Sat Jun 21 13:59:25 2014 +0200 +++ b/Lib/textwrap.py Sun Jun 22 14:35:10 2014 -0400 @@ -429,11 +429,16 @@ 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 + matches = [x == y for x, y in zip(margin, indent)] + result = "" + i = 0 + while matches[i]: + result += margin[i] + i += 1 + margin = result # sanity check (testing/debugging only) if 0 and margin: