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.