diff options
Diffstat (limited to 'django/utils/text.py')
| -rw-r--r-- | django/utils/text.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/django/utils/text.py b/django/utils/text.py index 81ae88dc76..b018f2601f 100644 --- a/django/utils/text.py +++ b/django/utils/text.py @@ -102,10 +102,19 @@ def wrap(text, width): width=width, break_long_words=False, break_on_hyphens=False, + replace_whitespace=False, ) result = [] - for line in text.splitlines(True): - result.extend(wrapper.wrap(line)) + for line in text.splitlines(): + wrapped = wrapper.wrap(line) + if not wrapped: + # If `line` contains only whitespaces that are dropped, restore it. + result.append(line) + else: + result.extend(wrapped) + if text.endswith("\n"): + # If `text` ends with a newline, preserve it. + result.append("") return "\n".join(result) |
