diff --git a/rest_framework/templatetags/rest_framework.py b/rest_framework/templatetags/rest_framework.py index 36aa9e8b30..3923389737 100644 --- a/rest_framework/templatetags/rest_framework.py +++ b/rest_framework/templatetags/rest_framework.py @@ -314,7 +314,7 @@ def smart_urlquote_wrapper(matched_url): return None -@register.filter +@register.filter(needs_autoescape=True) def urlize_quoted_links(text, trim_url_limit=None, nofollow=True, autoescape=True): """ Converts any URLs in text into clickable links. diff --git a/tests/test_templatetags.py b/tests/test_templatetags.py index dfbd5d9de0..5d4f6a4e3d 100644 --- a/tests/test_templatetags.py +++ b/tests/test_templatetags.py @@ -3,6 +3,7 @@ import unittest +from django.template import Context, Template from django.test import TestCase from rest_framework.compat import coreapi, coreschema @@ -304,6 +305,16 @@ def test_json_with_url(self): '"foo_set": [\n "http://api/foos/1/"\n], ' self._urlize_dict_check(data) + def test_template_render_with_noautoescape(self): + """ + Test if the autoescape value is getting passed to urlize_quoted_links filter. + """ + template = Template("{% load rest_framework %}" + "{% autoescape off %}{{ content|urlize_quoted_links }}" + "{% endautoescape %}") + rendered = template.render(Context({'content': '"http://example.com"'})) + assert rendered == '"http://example.com"' + @unittest.skipUnless(coreapi, 'coreapi is not installed') class SchemaLinksTests(TestCase):