diff -r fdfa15a9243c -r cb18733ce8f1 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 13:58:45 2014 -0400 @@ -732,6 +732,10 @@ 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?" + expect = " \thello there\n\thow are you?" + self.assertEqual(expect, dedent(text)) # Test textwrap.indent class IndentTestCase(unittest.TestCase): diff -r fdfa15a9243c -r cb18733ce8f1 Lib/textwrap.py --- a/Lib/textwrap.py Sat Jun 21 13:59:25 2014 +0200 +++ b/Lib/textwrap.py Sun Jun 22 13:58:45 2014 -0400 @@ -429,10 +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 = "" + matches = [x == y for x, y in zip(margin, indent)] + result = "" + i = 0 + while matches[i]: + result += margin[i] + i += 1 + margin = result break # sanity check (testing/debugging only)