Fixed #10834 -- Added bucket condition to ensure that URL resolvers won't ever return None. Thanks to Chris Cahoon for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11120 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee 2009-06-29 14:02:17 +00:00
parent e522e61a80
commit 735309341e
2 changed files with 18 additions and 1 deletions

View File

@ -195,6 +195,7 @@ class RegexURLResolver(object):
return sub_match[0], sub_match[1], sub_match_dict return sub_match[0], sub_match[1], sub_match_dict
tried.append(pattern.regex.pattern) tried.append(pattern.regex.pattern)
raise Resolver404, {'tried': tried, 'path': new_path} raise Resolver404, {'tried': tried, 'path': new_path}
raise Resolver404, {'tried': [], 'path' : path}
def _get_urlconf_module(self): def _get_urlconf_module(self):
try: try:

View File

@ -14,8 +14,9 @@ Traceback (most recent call last):
ImproperlyConfigured: The included urlconf regressiontests.urlpatterns_reverse.no_urls doesn't have any patterns in it ImproperlyConfigured: The included urlconf regressiontests.urlpatterns_reverse.no_urls doesn't have any patterns in it
"""} """}
import unittest
from django.core.urlresolvers import reverse, NoReverseMatch from django.core.urlresolvers import reverse, resolve, NoReverseMatch, Resolver404
from django.http import HttpResponseRedirect, HttpResponsePermanentRedirect from django.http import HttpResponseRedirect, HttpResponsePermanentRedirect
from django.shortcuts import redirect from django.shortcuts import redirect
from django.test import TestCase from django.test import TestCase
@ -112,6 +113,21 @@ class URLPatternReverse(TestCase):
else: else:
self.assertEquals(got, expected) self.assertEquals(got, expected)
class ResolverTests(unittest.TestCase):
def test_non_regex(self):
"""
Verifies that we raise a Resolver404 if what we are resolving doesn't
meet the basic requirements of a path to match - i.e., at the very
least, it matches the root pattern '^/'. We must never return None
from resolve, or we will get a TypeError further down the line.
Regression for #10834.
"""
self.assertRaises(Resolver404, resolve, '')
self.assertRaises(Resolver404, resolve, 'a')
self.assertRaises(Resolver404, resolve, '\\')
self.assertRaises(Resolver404, resolve, '.')
class ReverseShortcutTests(TestCase): class ReverseShortcutTests(TestCase):
urls = 'regressiontests.urlpatterns_reverse.urls' urls = 'regressiontests.urlpatterns_reverse.urls'