]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Remove unescape method for fixing concatenation issue 826/head
authorErik Johnson <palehose@gmail.com>
Tue, 20 Mar 2018 02:56:54 +0000 (21:56 -0500)
committerErik Johnson <palehose@gmail.com>
Tue, 20 Mar 2018 02:56:54 +0000 (21:56 -0500)
This ensures that we only concatenate Markup instances to other Markup
instances.

jinja2/filters.py

index 05a9902d762bb6d536ba8261da9f1b7daa69d60f..6d3e463f55178e8a7a3fd7475a18e1413afa6f11 100644 (file)
@@ -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