Ticket #6831: 0001-Replace-backslash-in-reverse-URL-resolver.patch

File 0001-Replace-backslash-in-reverse-URL-resolver.patch, 1.7 KB (added by Bastian Kleineidam <calvin@…>, 17 years ago)
  • django/core/urlresolvers.py

    From ae8e1f3afcf72e2e3ac841602143af5ebdba711e Mon Sep 17 00:00:00 2001
    From: Bastian Kleineidam <calvin@debian.org>
    Date: Tue, 18 Mar 2008 21:44:02 +0100
    Subject: Replace backslash in reverse URL resolver
    
    The reverse URL resolver replaces regular expression syntax characters,
    which should also include a backslash.
    
    Signed-off-by: Bastian Kleineidam <calvin@debian.org>
    
    diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py
    index 920b6c4..d3a2893 100644
    a b def reverse_helper(regex, *args, **kwargs):  
    8686    """
    8787    # TODO: Handle nested parenthesis in the following regex.
    8888    result = re.sub(r'\(([^)]+)\)', MatchChecker(args, kwargs), regex.pattern)
    89     return result.replace('^', '').replace('$', '')
     89    return result.replace('^', '').replace('$', '').replace('\\', '')
    9090
    9191class MatchChecker(object):
    9292    "Class used in reverse RegexURLPattern lookup."
  • tests/regressiontests/urlpatterns_reverse/tests.py

    diff --git a/tests/regressiontests/urlpatterns_reverse/tests.py b/tests/regressiontests/urlpatterns_reverse/tests.py
    index 8f571ac..610c3f7 100644
    a b test_data = (  
    1717    ('^hardcoded/$', 'hardcoded/', [], {}),
    1818    ('^hardcoded/$', 'hardcoded/', ['any arg'], {}),
    1919    ('^hardcoded/$', 'hardcoded/', [], {'kwarg': 'foo'}),
     20    ('^hardcoded/doc\\.pdf$', 'hardcoded/doc.pdf', [], {}),
    2021    ('^people/(?P<state>\w\w)/(?P<name>\w+)/$', 'people/il/adrian/', [], {'state': 'il', 'name': 'adrian'}),
    2122    ('^people/(?P<state>\w\w)/(?P<name>\d)/$', NoReverseMatch, [], {'state': 'il', 'name': 'adrian'}),
    2223    ('^people/(?P<state>\w\w)/(?P<name>\w+)/$', NoReverseMatch, [], {'state': 'il'}),
Back to Top