Skip to content

Commit

Permalink
Fixed #8725 -- Handle empty URL patterns in reverse().
Browse files Browse the repository at this point in the history
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8763 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
malcolmt committed Aug 31, 2008
1 parent 30c7ce9 commit e1ea701
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion django/utils/regex_helper.py
Expand Up @@ -74,7 +74,11 @@ def normalize(pattern):
# A "while" loop is used here because later on we need to be able to peek
# at the next character and possibly go around without consuming another
# one at the top of the loop.
ch, escaped = pattern_iter.next()
try:
ch, escaped = pattern_iter.next()
except StopIteration:
return zip([''], [[]])

try:
while True:
if escaped:
Expand Down
11 changes: 11 additions & 0 deletions tests/regressiontests/urlpatterns_reverse/extra_urls.py
@@ -0,0 +1,11 @@
"""
Some extra URL patterns that are included at the top level.
"""

from django.conf.urls.defaults import *
from views import empty_view

urlpatterns = patterns('',
url(r'^e-places/(\d+)/$', empty_view, name='extra-places'),
url(r'^e-people/(?P<name>\w+)/$', empty_view, name="extra-people"),
)
3 changes: 3 additions & 0 deletions tests/regressiontests/urlpatterns_reverse/tests.py
Expand Up @@ -61,6 +61,9 @@
('inner-extra', NoReverseMatch, ['fred', 'inner'], {}),
('disjunction', NoReverseMatch, ['foo'], {}),
('inner-disjunction', NoReverseMatch, ['10', '11'], {}),
('extra-places', '/e-places/10/', ['10'], {}),
('extra-people', '/e-people/fred/', ['fred'], {}),
('extra-people', '/e-people/fred/', [], {'name': 'fred'}),
)

class URLPatternReverse(TestCase):
Expand Down
1 change: 1 addition & 0 deletions tests/regressiontests/urlpatterns_reverse/urls.py
Expand Up @@ -40,6 +40,7 @@
url(r'^(?i)test/2/?$', empty_view, name="test2"),
url(r'^outer/(?P<outer>\d+)/',
include('regressiontests.urlpatterns_reverse.included_urls')),
url('', include('regressiontests.urlpatterns_reverse.extra_urls')),

# This is non-reversible, but we shouldn't blow up when parsing it.
url(r'^(?:foo|bar)(\w+)/$', empty_view, name="disjunction"),
Expand Down

0 comments on commit e1ea701

Please sign in to comment.