From 2e9e36e29744ca638ca34799d79a6eb638a2d822 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Tue, 20 Nov 2007 01:37:57 +0000 Subject: [PATCH] Fixed #5983 -- Made iriencode filter respect safe strings. Patch from SmileyChris. git-svn-id: http://code.djangoproject.com/svn/django/trunk@6706 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/template/defaultfilters.py | 1 + tests/regressiontests/templates/filters.py | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index 7d4a72efb3..76d723e0eb 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -106,6 +106,7 @@ floatformat.is_safe = True def iriencode(value): """Escapes an IRI value for use in a URL.""" return force_unicode(iri_to_uri(value)) +iriencode.is_safe = True iriencode = stringfilter(iriencode) def linenumbers(value, autoescape=None): diff --git a/tests/regressiontests/templates/filters.py b/tests/regressiontests/templates/filters.py index 27b24cb169..2a06703948 100644 --- a/tests/regressiontests/templates/filters.py +++ b/tests/regressiontests/templates/filters.py @@ -198,6 +198,12 @@ def get_filter_tests(): 'filter-phone2numeric01': ('{{ a|phone2numeric }} {{ b|phone2numeric }}', {"a": "<1-800-call-me>", "b": mark_safe("<1-800-call-me>") }, "<1-800-2255-63> <1-800-2255-63>"), 'filter-phone2numeric02': ('{% autoescape off %}{{ a|phone2numeric }} {{ b|phone2numeric }}{% endautoescape %}', {"a": "<1-800-call-me>", "b": mark_safe("<1-800-call-me>") }, "<1-800-2255-63> <1-800-2255-63>"), + # Ensure iriencode keeps safe strings: + 'filter-iriencode01': ('{{ url|iriencode }}', {'url': '?test=1&me=2'}, '?test=1&me=2'), + 'filter-iriencode02': ('{% autoescape off %}{{ url|iriencode }}{% endautoescape %}', {'url': '?test=1&me=2'}, '?test=1&me=2'), + 'filter-iriencode03': ('{{ url|iriencode }}', {'url': mark_safe('?test=1&me=2')}, '?test=1&me=2'), + 'filter-iriencode04': ('{% autoescape off %}{{ url|iriencode }}{% endautoescape %}', {'url': mark_safe('?test=1&me=2')}, '?test=1&me=2'), + # Chaining a bunch of safeness-preserving filters should not alter # the safe status either way. 'chaining01': ('{{ a|capfirst|center:"7" }}.{{ b|capfirst|center:"7" }}', {"a": "a < b", "b": mark_safe("a < b")}, " A < b . A < b "),