diff -r 09105051b9f4 Lib/test/test_textwrap.py --- a/Lib/test/test_textwrap.py Sun Nov 03 21:31:38 2013 +0200 +++ b/Lib/test/test_textwrap.py Wed Nov 06 19:47:24 2013 +0000 @@ -732,6 +732,14 @@ expect = "hello there\n how are you?" self.assertEqual(expect, dedent(text)) + def test_dedent_works_with_lf_and_crlf(self): + lf = ' a\n b\n\n c' + expect = 'a\nb\n\nc' + self.assertEqual(expect, dedent(lf)) + + crlf = lf.replace('\n', '\r\n') + expect = expect.replace('\n', '\r\n') + self.assertEqual(expect, dedent(crlf)) # Test textwrap.indent class IndentTestCase(unittest.TestCase): diff -r 09105051b9f4 Lib/textwrap.py --- a/Lib/textwrap.py Sun Nov 03 21:31:38 2013 +0200 +++ b/Lib/textwrap.py Wed Nov 06 19:47:24 2013 +0000 @@ -395,7 +395,8 @@ # -- Loosely related functionality ------------------------------------- _whitespace_only_re = re.compile('^[ \t]+$', re.MULTILINE) -_leading_whitespace_re = re.compile('(^[ \t]*)(?:[^ \t\n])', re.MULTILINE) +_leading_whitespace_re = re.compile('(^[ \t]*)[^\r\n]', re.MULTILINE) + def dedent(text): """Remove any common leading whitespace from every line in `text`.