Skip to content

Commit

Permalink
Renamed urlescape to urlencode
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Jan 7, 2012
1 parent 1d4c638 commit 5145401
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CHANGES
Expand Up @@ -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.

Expand Down
12 changes: 6 additions & 6 deletions jinja2/filters.py
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions jinja2/testsuite/filters.py
Expand Up @@ -367,11 +367,11 @@ def test_safe(self):
tmpl = env.from_string('{{ "<div>foo</div>" }}')
assert tmpl.render() == '&lt;div&gt;foo&lt;/div&gt;'

def test_urlescape(self):
def test_urlencode(self):
env = Environment(autoescape=True)
tmpl = env.from_string('{{ "Hello, world!"|urlescape }}')
tmpl = env.from_string('{{ "Hello, world!"|urlencode }}')
assert tmpl.render() == 'Hello%2C%20world%21'
tmpl = env.from_string('{{ o|urlescape }}')
tmpl = env.from_string('{{ o|urlencode }}')
assert tmpl.render(o=u"Hello, world\u203d") == "Hello%2C%20world%E2%80%BD"
assert tmpl.render(o=(("f", 1),)) == "f=1"
assert tmpl.render(o=(('f', 1), ("z", 2))) == "f=1&amp;z=2"
Expand Down
2 changes: 1 addition & 1 deletion jinja2/utils.py
Expand Up @@ -353,7 +353,7 @@ def generate_lorem_ipsum(n=5, html=True, min=20, max=100):
return Markup(u'\n'.join(u'<p>%s</p>' % 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.
Expand Down

0 comments on commit 5145401

Please sign in to comment.