Opened 18 years ago
Closed 18 years ago
#3714 closed (fixed)
django.utils.text.wrap() does not properly handle indented text
Reported by: | Bryan Chow | Owned by: | Adrian Holovaty |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
wrap() in django.utils.text does not properly handle indented lines of text. When it encounters a line that begins with spaces, it fails to reset the character position counter and thus miscalculates the length of that line. This is due to the use of splitline() on line 20; substituting split('\n') for splitline() resolves this issue.
On line 14 of text.py, the text to be wrapped is split on spaces into words. Therefore, if a line is indented, a word ending with a line break will be encountered.
'word\n'.splitlines()
returns ['word']
'word\n'.split('\n')
returns ['word', '']
In the former case, the empty string representing the first word of the next line is disregarded, and thus the test on line 29 doesn't notice that a new line has started.
Attachments (2)
Change History (7)
by , 18 years ago
Attachment: | text-wrap.patch added |
---|
comment:1 by , 18 years ago
Has patch: | set |
---|
comment:2 by , 18 years ago
Needs tests: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
Could we have a test for this please?
comment:3 by , 18 years ago
Needs tests: | unset |
---|
I've added a couple of doctests with this attachment, testing for the indentation behaviour, as well as looking for off-by-one wrapping errors.
comment:4 by , 18 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:5 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Fix for word wrap problem