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):
|
86 | 86 | """ |
87 | 87 | # TODO: Handle nested parenthesis in the following regex. |
88 | 88 | result = re.sub(r'\(([^)]+)\)', MatchChecker(args, kwargs), regex.pattern) |
89 | | return result.replace('^', '').replace('$', '') |
| 89 | return result.replace('^', '').replace('$', '').replace('\\', '') |
90 | 90 | |
91 | 91 | class MatchChecker(object): |
92 | 92 | "Class used in reverse RegexURLPattern lookup." |
diff --git a/tests/regressiontests/urlpatterns_reverse/tests.py b/tests/regressiontests/urlpatterns_reverse/tests.py
index 8f571ac..610c3f7 100644
a
|
b
|
test_data = (
|
17 | 17 | ('^hardcoded/$', 'hardcoded/', [], {}), |
18 | 18 | ('^hardcoded/$', 'hardcoded/', ['any arg'], {}), |
19 | 19 | ('^hardcoded/$', 'hardcoded/', [], {'kwarg': 'foo'}), |
| 20 | ('^hardcoded/doc\\.pdf$', 'hardcoded/doc.pdf', [], {}), |
20 | 21 | ('^people/(?P<state>\w\w)/(?P<name>\w+)/$', 'people/il/adrian/', [], {'state': 'il', 'name': 'adrian'}), |
21 | 22 | ('^people/(?P<state>\w\w)/(?P<name>\d)/$', NoReverseMatch, [], {'state': 'il', 'name': 'adrian'}), |
22 | 23 | ('^people/(?P<state>\w\w)/(?P<name>\w+)/$', NoReverseMatch, [], {'state': 'il'}), |