Skip to content

Commit 34a2352

Browse files
committed
Make sure wordwrap() and friend works as intended if they are used as template filters and given string arguments.
- Legacy-Id: 13653
1 parent 4ea1c34 commit 34a2352

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

ietf/utils/text.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def wordwrap(text, width=80):
5757
of short lines"""
5858
if not isinstance(text, (types.StringType,types.UnicodeType)):
5959
return text
60+
width = int(width) # ensure we have an int, if this is used as a template filter
6061
text = re.sub(" *\r\n", "\n", text) # get rid of DOS line endings
6162
text = re.sub(" *\r", "\n", text) # get rid of MAC line endings
6263
text = re.sub("( *\n){3,}", "\n\n", text) # get rid of excessive vertical whitespace
@@ -107,6 +108,9 @@ def wrap_text_if_unwrapped(text, width=80, max_tolerated_line_length=100):
107108
text = re.sub(" *\r\n", "\n", text) # get rid of DOS line endings
108109
text = re.sub(" *\r", "\n", text) # get rid of MAC line endings
109110

111+
width = int(width) # ensure we have an int, if this is used as a template filter
112+
max_tolerated_line_length = int(max_tolerated_line_length)
113+
110114
contains_long_lines = any(" " in l and len(l) > max_tolerated_line_length
111115
for l in text.split("\n"))
112116

0 commit comments

Comments
 (0)