mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 17:47:04 +03:00
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:
parent
5feb835929
commit
dd19a44583
|
@ -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.
|
||||
|
|
|
@ -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):
|
|||
'"foo_set": [\n "<a href="http://api/foos/1/">http://api/foos/1/</a>"\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):
|
||||
|
|
Loading…
Reference in New Issue
Block a user