Ticket #13765: 13765.diff

File 13765.diff, 3.7 KB (added by Chris Beaven, 14 years ago)
  • django/template/defaultfilters.py

    diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py
    index 4b72009..1880dbe 100644
    a b def upper(value):  
    286286upper.is_safe = False
    287287upper = stringfilter(upper)
    288288
    289 def urlencode(value):
    290     """Escapes a value for use in a URL."""
     289def 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    """
    291298    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)
    293303urlencode.is_safe = False
    294304urlencode = stringfilter(urlencode)
    295305
  • django/utils/http.py

    diff --git a/django/utils/http.py b/django/utils/http.py
    index f0b1af9..610fcbf 100644
    a b def urlquote(url, safe='/'):  
    1414    can safely be used as part of an argument to a subsequent iri_to_uri() call
    1515    without double-quoting occurring.
    1616    """
    17     return force_unicode(urllib.quote(smart_str(url), safe))
     17    return force_unicode(urllib.quote(smart_str(url), smart_str(safe)))
    1818
    1919urlquote = allow_lazy(urlquote, unicode)
    2020
    def urlquote_plus(url, safe=''):  
    2525    returned string can safely be used as part of an argument to a subsequent
    2626    iri_to_uri() call without double-quoting occurring.
    2727    """
    28     return force_unicode(urllib.quote_plus(smart_str(url), safe))
     28    return force_unicode(urllib.quote_plus(smart_str(url), smart_str(safe)))
    2929urlquote_plus = allow_lazy(urlquote_plus, unicode)
    3030
    3131def urlencode(query, doseq=0):
  • docs/ref/templates/builtins.txt

    diff --git a/docs/ref/templates/builtins.txt b/docs/ref/templates/builtins.txt
    index 002aa3f..00add09 100644
    a b For example::  
    19591959If ``value`` is ``"http://www.example.org/foo?a=b&c=d"``, the output will be
    19601960``"http%3A//www.example.org/foo%3Fa%3Db%26c%3Dd"``.
    19611961
     1962.. versionadded:: 1.1
     1963
     1964An optional argument containing the characters which should not be escaped can
     1965be provided.
     1966
     1967If not provided, the '/' character is assumed safe. An empty string can be
     1968provided when *all* characters should be escaped. For example::
     1969
     1970    {{ value|urlencode:"" }}
     1971
     1972If ``value`` is ``"http://www.example.org/"``, the output will be
     1973``"http%3A%2F%2Fwww.example.org%2F"``.
     1974
    19621975.. templatefilter:: urlize
    19631976
    19641977urlize
  • tests/regressiontests/templates/filters.py

    diff --git a/tests/regressiontests/templates/filters.py b/tests/regressiontests/templates/filters.py
    index 3d6284e..8ce1bce 100644
    a b def get_filter_tests():  
    265265        'filter-iriencode03': ('{{ url|iriencode }}', {'url': mark_safe('?test=1&me=2')}, '?test=1&me=2'),
    266266        'filter-iriencode04': ('{% autoescape off %}{{ url|iriencode }}{% endautoescape %}', {'url': mark_safe('?test=1&me=2')}, '?test=1&me=2'),
    267267
     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
    268272        # Chaining a bunch of safeness-preserving filters should not alter
    269273        # the safe status either way.
    270274        'chaining01': ('{{ a|capfirst|center:"7" }}.{{ b|capfirst|center:"7" }}', {"a": "a < b", "b": mark_safe("a < b")}, " A &lt; b . A < b "),
Back to Top