diff --git a/CHANGES b/CHANGES index 8838a2154..a48208a3f 100644 --- a/CHANGES +++ b/CHANGES @@ -10,7 +10,7 @@ Version 2.7 advertised. - Fixed filesizeformat. - Added a non-silent option for babel extraction. -- Added `urlescape` filter that automatically quotes values for +- Added `urlencode` filter that automatically quotes values for URL safe usage with utf-8 as only supported encoding. If applications want to change this encoding they can override the filter. diff --git a/jinja2/filters.py b/jinja2/filters.py index bbe5a8cd8..8dd6ff07f 100644 --- a/jinja2/filters.py +++ b/jinja2/filters.py @@ -14,7 +14,7 @@ from operator import itemgetter from itertools import imap, groupby from jinja2.utils import Markup, escape, pformat, urlize, soft_unicode, \ - unicode_urlescape + unicode_urlencode from jinja2.runtime import Undefined from jinja2.exceptions import FilterArgumentError @@ -71,7 +71,7 @@ def do_forceescape(value): return escape(unicode(value)) -def do_urlescape(value): +def do_urlencode(value): """Escape strings for use in URLs (uses UTF-8 encoding). It accepts both dictionaries and regular strings as well as pairwise iterables. @@ -86,9 +86,9 @@ def do_urlescape(value): except TypeError: pass if itemiter is None: - return unicode_urlescape(value) - return u'&'.join(unicode_urlescape(k) + '=' + - unicode_urlescape(v) for k, v in itemiter) + return unicode_urlencode(value) + return u'&'.join(unicode_urlencode(k) + '=' + + unicode_urlencode(v) for k, v in itemiter) @evalcontextfilter @@ -819,5 +819,5 @@ def do_attr(environment, obj, name): 'groupby': do_groupby, 'safe': do_mark_safe, 'xmlattr': do_xmlattr, - 'urlescape': do_urlescape + 'urlencode': do_urlencode } diff --git a/jinja2/testsuite/filters.py b/jinja2/testsuite/filters.py index 15451e594..94bc02af6 100644 --- a/jinja2/testsuite/filters.py +++ b/jinja2/testsuite/filters.py @@ -367,11 +367,11 @@ def test_safe(self): tmpl = env.from_string('{{ "
%s
' % escape(x) for x in result)) -def unicode_urlescape(obj, charset='utf-8'): +def unicode_urlencode(obj, charset='utf-8'): """URL escapes a single bytestring or unicode string with the given charset if applicable to URL safe quoting under all rules that need to be considered under all supported Python versions.