Ticket #13260: t13260-patch.diff

File t13260-patch.diff, 3.3 KB (added by stumbles, 14 years ago)

Additional tests including russellm's above plus one additional, code + test change assuming urlquote should be applied to args and kwargs.

  • django/core/urlresolvers.py

     
    1515from django.utils.datastructures import MultiValueDict
    1616from django.utils.encoding import iri_to_uri, force_unicode, smart_str
    1717from django.utils.functional import memoize
     18from django.utils.http import urlquote
    1819from django.utils.importlib import import_module
    1920from django.utils.regex_helper import normalize
    2021from django.utils.thread_support import currentThread
     
    274275                if args:
    275276                    if len(args) != len(params):
    276277                        continue
    277                     unicode_args = [force_unicode(val) for val in args]
     278                    unicode_args = [urlquote(force_unicode(val)) for val in args]
    278279                    candidate =  result % dict(zip(params, unicode_args))
    279280                else:
    280281                    if set(kwargs.keys()) != set(params):
    281282                        continue
    282                     unicode_kwargs = dict([(k, force_unicode(v)) for (k, v) in kwargs.items()])
     283                    unicode_kwargs = dict([(k, urlquote(force_unicode(v))) for (k, v) in kwargs.items()])
    283284                    candidate = result % unicode_kwargs
    284285                if re.search(u'^%s' % pattern, candidate, re.UNICODE):
    285286                    return candidate
  • tests/regressiontests/urlpatterns_reverse/tests.py

     
    6767    ('product', '/product/chocolate+($2.00)/', [], {'price': '2.00', 'product': 'chocolate'}),
    6868    ('headlines', '/headlines/2007.5.21/', [], dict(year=2007, month=5, day=21)),
    6969    ('windows', r'/windows_path/C:%5CDocuments%20and%20Settings%5Cspam/', [], dict(drive_name='C', path=r'Documents and Settings\spam')),
    70     ('special', r'/special_chars/+%5C$*/', [r'+\$*'], {}),
     70    ('special', r'/special_chars/%2B%5C%24%2A/', [r'+\$*'], {}),
     71    ('special', r'/special_chars/some%20resource/', [r'some resource'], {}),
     72    ('special', r'/special_chars/10%25%20complete/', [r'10% complete'], {}),
     73    ('special', r'/special_chars/some%20resource/', [], {'chars': r'some resource'}),
     74    ('special', r'/special_chars/10%25%20complete/', [], {'chars': r'10% complete'}),
    7175    ('special', NoReverseMatch, [''], {}),
    7276    ('mixed', '/john/0/', [], {'name': 'john'}),
    7377    ('repeats', '/repeats/a/', [], {}),
  • tests/regressiontests/urlpatterns_reverse/urls.py

     
    3535            name="headlines"),
    3636    url(r'^windows_path/(?P<drive_name>[A-Z]):\\(?P<path>.+)/$', empty_view,
    3737            name="windows"),
    38     url(r'^special_chars/(.+)/$', empty_view, name="special"),
     38    url(r'^special_chars/(?P<chars>.+)/$', empty_view, name="special"),
    3939    url(r'^(?P<name>.+)/\d+/$', empty_view, name="mixed"),
    4040    url(r'^repeats/a{1,2}/$', empty_view, name="repeats"),
    4141    url(r'^repeats/a{2,4}/$', empty_view, name="repeats2"),
Back to Top