diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py
index 4b72009..1880dbe 100644
a
|
b
|
def upper(value):
|
286 | 286 | upper.is_safe = False |
287 | 287 | upper = stringfilter(upper) |
288 | 288 | |
289 | | def urlencode(value): |
290 | | """Escapes a value for use in a URL.""" |
| 289 | def urlencode(value, safe=None): |
| 290 | """ |
| 291 | Escapes a value for use in a URL. |
| 292 | |
| 293 | Takes an optional ``safe`` parameter used to determine the characters which |
| 294 | should not be escaped by Django's ``urlquote`` method. If not provided, the |
| 295 | default safe characters will be used (but an empty string can be provided |
| 296 | when *all* characters should be escaped). |
| 297 | """ |
291 | 298 | from django.utils.http import urlquote |
292 | | return urlquote(value) |
| 299 | kwargs = {} |
| 300 | if safe is not None: |
| 301 | kwargs['safe'] = safe |
| 302 | return urlquote(value, **kwargs) |
293 | 303 | urlencode.is_safe = False |
294 | 304 | urlencode = stringfilter(urlencode) |
295 | 305 | |
diff --git a/django/utils/http.py b/django/utils/http.py
index f0b1af9..610fcbf 100644
a
|
b
|
def urlquote(url, safe='/'):
|
14 | 14 | can safely be used as part of an argument to a subsequent iri_to_uri() call |
15 | 15 | without double-quoting occurring. |
16 | 16 | """ |
17 | | return force_unicode(urllib.quote(smart_str(url), safe)) |
| 17 | return force_unicode(urllib.quote(smart_str(url), smart_str(safe))) |
18 | 18 | |
19 | 19 | urlquote = allow_lazy(urlquote, unicode) |
20 | 20 | |
… |
… |
def urlquote_plus(url, safe=''):
|
25 | 25 | returned string can safely be used as part of an argument to a subsequent |
26 | 26 | iri_to_uri() call without double-quoting occurring. |
27 | 27 | """ |
28 | | return force_unicode(urllib.quote_plus(smart_str(url), safe)) |
| 28 | return force_unicode(urllib.quote_plus(smart_str(url), smart_str(safe))) |
29 | 29 | urlquote_plus = allow_lazy(urlquote_plus, unicode) |
30 | 30 | |
31 | 31 | def urlencode(query, doseq=0): |
diff --git a/docs/ref/templates/builtins.txt b/docs/ref/templates/builtins.txt
index 002aa3f..00add09 100644
a
|
b
|
For example::
|
1959 | 1959 | If ``value`` is ``"http://www.example.org/foo?a=b&c=d"``, the output will be |
1960 | 1960 | ``"http%3A//www.example.org/foo%3Fa%3Db%26c%3Dd"``. |
1961 | 1961 | |
| 1962 | .. versionadded:: 1.1 |
| 1963 | |
| 1964 | An optional argument containing the characters which should not be escaped can |
| 1965 | be provided. |
| 1966 | |
| 1967 | If not provided, the '/' character is assumed safe. An empty string can be |
| 1968 | provided when *all* characters should be escaped. For example:: |
| 1969 | |
| 1970 | {{ value|urlencode:"" }} |
| 1971 | |
| 1972 | If ``value`` is ``"http://www.example.org/"``, the output will be |
| 1973 | ``"http%3A%2F%2Fwww.example.org%2F"``. |
| 1974 | |
1962 | 1975 | .. templatefilter:: urlize |
1963 | 1976 | |
1964 | 1977 | urlize |
diff --git a/tests/regressiontests/templates/filters.py b/tests/regressiontests/templates/filters.py
index 3d6284e..8ce1bce 100644
a
|
b
|
def get_filter_tests():
|
265 | 265 | 'filter-iriencode03': ('{{ url|iriencode }}', {'url': mark_safe('?test=1&me=2')}, '?test=1&me=2'), |
266 | 266 | 'filter-iriencode04': ('{% autoescape off %}{{ url|iriencode }}{% endautoescape %}', {'url': mark_safe('?test=1&me=2')}, '?test=1&me=2'), |
267 | 267 | |
| 268 | # urlencode |
| 269 | 'filter-urlencode01': ('{{ url|urlencode }}', {'url': '/test&"/me?/'}, '/test%26%22/me%3F/'), |
| 270 | 'filter-urlencode02': ('/test/{{ urlbit|urlencode:"" }}/', {'urlbit': 'escape/slash'}, '/test/escape%2Fslash/'), |
| 271 | |
268 | 272 | # Chaining a bunch of safeness-preserving filters should not alter |
269 | 273 | # the safe status either way. |
270 | 274 | 'chaining01': ('{{ a|capfirst|center:"7" }}.{{ b|capfirst|center:"7" }}', {"a": "a < b", "b": mark_safe("a < b")}, " A < b . A < b "), |