From a2f5e2c7972c4d5148c1c75c724e24950d8605bc Mon Sep 17 00:00:00 2001 From: Erik Johnson Date: Mon, 19 Mar 2018 21:56:54 -0500 Subject: [PATCH] Remove unescape method for fixing concatenation issue This ensures that we only concatenate Markup instances to other Markup instances. --- jinja2/filters.py | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/jinja2/filters.py b/jinja2/filters.py index 05a9902d..6d3e463f 100644 --- a/jinja2/filters.py +++ b/jinja2/filters.py @@ -554,31 +554,25 @@ def do_indent( ), stacklevel=2) first = indentfirst - s += u'\n' # this quirk is necessary for splitlines method indention = u' ' * width + newline = u'\n' - def _unescape(val): - ''' - Unescape any strings that were escaped due to concatenation. If the - value passed is not a Markup instance, return the original value. - ''' - try: - return Markup(val.unescape()) - except AttributeError: - # s was not a Markup instance - return val + if isinstance(s, Markup): + indention = Markup(indention) + newline = Markup(newline) + + s += newline # this quirk is necessary for splitlines method if blank: - rv = _unescape((u'\n' + indention).join(s.splitlines())) + rv = (newline + indention).join(s.splitlines()) else: lines = s.splitlines() rv = lines.pop(0) if lines: - rv += u'\n' + u'\n'.join( + rv += newline + newline.join( indention + line if line else line for line in lines ) - rv = _unescape(rv) if first: rv = indention + rv -- 2.47.2