From c2a1af883e18b93a77080650feb9e959536d51ca Mon Sep 17 00:00:00 2001 From: Ryan Rubin Date: Fri, 25 May 2018 10:11:46 -0500 Subject: [2.0.x] Fixed #29400 -- Fixed crash in custom template filters that use decorated functions. Regression in 620e9dd31a2146d70de740f96a8cb9a6db054fc7. Backport of a8d12bc28069d56e0306770ab9c73738293663f7 from master --- tests/template_tests/templatetags/custom.py | 8 ++++++++ tests/template_tests/test_custom.py | 5 +++++ 2 files changed, 13 insertions(+) (limited to 'tests') diff --git a/tests/template_tests/templatetags/custom.py b/tests/template_tests/templatetags/custom.py index 2e2ccf3782..45acd9655e 100644 --- a/tests/template_tests/templatetags/custom.py +++ b/tests/template_tests/templatetags/custom.py @@ -3,6 +3,7 @@ import operator from django import template from django.template.defaultfilters import stringfilter from django.utils.html import escape, format_html +from django.utils.safestring import mark_safe register = template.Library() @@ -13,6 +14,13 @@ def trim(value, num): return value[:num] +@register.filter +@mark_safe +def make_data_div(value): + """A filter that uses a decorator (@mark_safe).""" + return '
' % value + + @register.filter def noop(value, param=None): """A noop filter that always return its first argument and does nothing with diff --git a/tests/template_tests/test_custom.py b/tests/template_tests/test_custom.py index b37b5f8f1e..dbc5bc267d 100644 --- a/tests/template_tests/test_custom.py +++ b/tests/template_tests/test_custom.py @@ -25,6 +25,11 @@ class CustomFilterTests(SimpleTestCase): "abcde" ) + def test_decorated_filter(self): + engine = Engine(libraries=LIBRARIES) + t = engine.from_string('{% load custom %}{{ name|make_data_div }}') + self.assertEqual(t.render(Context({'name': 'foo'})), '
') + class TagTestCase(SimpleTestCase): -- cgit v1.3