summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
Diffstat (limited to 'django')
-rw-r--r--django/template/defaultfilters.py10
-rw-r--r--django/utils/encoding.py5
2 files changed, 12 insertions, 3 deletions
diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py
index e85780ab79..6414724c64 100644
--- a/django/template/defaultfilters.py
+++ b/django/template/defaultfilters.py
@@ -3,7 +3,7 @@
from django.template import resolve_variable, Library
from django.conf import settings
from django.utils.translation import ugettext, ungettext
-from django.utils.encoding import smart_unicode, smart_str
+from django.utils.encoding import smart_unicode, smart_str, iri_to_uri
import re
import random as random_module
@@ -84,6 +84,11 @@ def floatformat(text, arg=-1):
formatstr = u'%%.%df' % abs(d)
return formatstr % f
+def iriencode(value):
+ "Escapes an IRI value for use in a URL"
+ return smart_unicode(iri_to_uri(value))
+iriencode = stringfilter(iriencode)
+
def linenumbers(value):
"Displays text with line numbers"
from django.utils.html import escape
@@ -170,7 +175,7 @@ upper = stringfilter(upper)
def urlencode(value):
"Escapes a value for use in a URL"
import urllib
- return smart_unicode(urllib.quote(smart_str(value)))
+ return smart_unicode(urllib.quote(value))
urlencode = stringfilter(urlencode)
def urlize(value):
@@ -566,6 +571,7 @@ register.filter(first)
register.filter(fix_ampersands)
register.filter(floatformat)
register.filter(get_digit)
+register.filter(iriencode)
register.filter(join)
register.filter(length)
register.filter(length_is)
diff --git a/django/utils/encoding.py b/django/utils/encoding.py
index 7466e02300..5bb23a28bf 100644
--- a/django/utils/encoding.py
+++ b/django/utils/encoding.py
@@ -66,5 +66,8 @@ def iri_to_uri(iri):
Returns an ASCII string containing the encoded result.
"""
- return urllib.quote(smart_str(iri), safe='/#%[]')
+ # The list of safe characters here is constructed from the printable ASCII
+ # characters that are not explicitly excluded by the list at the end of
+ # section 3.1 of RFC 3987.
+ return urllib.quote(smart_str(iri), safe='/#%[]=:;$&()+,!?')