Problem: autoescape not getting passed to urlize_quoted_links filter (#6191)

Solution: set needs_autoescape=True when registering the filter

Without this patch, the disabling autoescape in the template does not work.
This commit is contained in:
Dennis Kliban 2018-10-10 04:36:04 -04:00 committed by Carlton Gibson
parent 5feb835929
commit dd19a44583
2 changed files with 12 additions and 1 deletions

View File

@ -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.

View File

@ -3,6 +3,7 @@ from __future__ import unicode_literals
import unittest
from django.template import Context, Template
from django.test import TestCase
from rest_framework.compat import coreapi, coreschema
@ -304,6 +305,16 @@ class URLizerTests(TestCase):
'&quot;foo_set&quot;: [\n &quot;<a href="http://api/foos/1/">http://api/foos/1/</a>&quot;\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 == '"<a href="http://example.com" rel="nofollow">http://example.com</a>"'
@unittest.skipUnless(coreapi, 'coreapi is not installed')
class SchemaLinksTests(TestCase):