This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author alexis.d
Recipients alexis.d
Date 2013-11-02.14:50:17
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1383403818.41.0.713007913793.issue19479@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2013-11-02 14:50:18alexis.dsetrecipients: + alexis.d
2013-11-02 14:50:18alexis.dsetmessageid: <1383403818.41.0.713007913793.issue19479@psf.upfronthosting.co.za>
2013-11-02 14:50:18alexis.dlinkissue19479 messages
2013-11-02 14:50:17alexis.dcreate