New submission from Alexis Daboville: If a string contains an empty line and is using CRLF newlines instead of LF newlines textwrap.dedent doesn't work properly: it returns the original string w/o dedenting it.
As far as I can tell it's because it considers the empty string to be the longest common indent (http://hg.python.org/cpython/file/2.7/Lib/textwrap.py#l372, '[^ \t\n]' matches '\r'). Expected behavior: textwrap.dedent should work the same way whether lines are separated by a single LF character or by CRLF. To repro: ✓ 15:26 dabovill @ morag in /tmp/dedent $ cat dedent.py import textwrap lf = '\ta\n\tb\n\n\tc' crlf = '\ta\r\n\tb\r\n\r\n\tc' print('- lf') print(lf) print('- dedent(lf)') print(textwrap.dedent(lf)) print('- crlf') print(crlf) print('- dedent(crlf)') print(textwrap.dedent(crlf)) ✓ 15:26 dabovill @ morag in /tmp/dedent $ python2.7 dedent.py - lf a b c - dedent(lf) a b c - crlf a b c - dedent(crlf) a b c ✓ 15:26 dabovill @ morag in /tmp/dedent $ python3.3 dedent.py - lf a b c - dedent(lf) a b c - crlf a b c - dedent(crlf) a b c ---------- components: Library (Lib) messages: 201975 nosy: alexis.d priority: normal severity: normal status: open title: textwrap.dedent doesn't work properly with strings containing CRLF type: behavior versions: Python 2.7, Python 3.3 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue19479> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com