From 34a23522888e88dbff039f71c60dacc50383a41c Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Fri, 16 Jun 2017 13:15:02 +0000 Subject: [PATCH] Make sure wordwrap() and friend works as intended if they are used as template filters and given string arguments. - Legacy-Id: 13653 --- ietf/utils/text.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ietf/utils/text.py b/ietf/utils/text.py index 8508aefc5..c19852e0c 100644 --- a/ietf/utils/text.py +++ b/ietf/utils/text.py @@ -57,6 +57,7 @@ def wordwrap(text, width=80): of short lines""" if not isinstance(text, (types.StringType,types.UnicodeType)): return text + width = int(width) # ensure we have an int, if this is used as a template filter text = re.sub(" *\r\n", "\n", text) # get rid of DOS line endings text = re.sub(" *\r", "\n", text) # get rid of MAC line endings 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): text = re.sub(" *\r\n", "\n", text) # get rid of DOS line endings text = re.sub(" *\r", "\n", text) # get rid of MAC line endings + width = int(width) # ensure we have an int, if this is used as a template filter + max_tolerated_line_length = int(max_tolerated_line_length) + contains_long_lines = any(" " in l and len(l) > max_tolerated_line_length for l in text.split("\n"))