diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py index ac83756f31..b3dcfdb8c1 100644 --- a/django/core/urlresolvers.py +++ b/django/core/urlresolvers.py @@ -195,6 +195,7 @@ class RegexURLResolver(object): return sub_match[0], sub_match[1], sub_match_dict tried.append(pattern.regex.pattern) raise Resolver404, {'tried': tried, 'path': new_path} + raise Resolver404, {'tried': [], 'path' : path} def _get_urlconf_module(self): try: diff --git a/tests/regressiontests/urlpatterns_reverse/tests.py b/tests/regressiontests/urlpatterns_reverse/tests.py index a7283d43bb..9def6b2eb2 100644 --- a/tests/regressiontests/urlpatterns_reverse/tests.py +++ b/tests/regressiontests/urlpatterns_reverse/tests.py @@ -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 """} +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.shortcuts import redirect from django.test import TestCase @@ -112,6 +113,21 @@ class URLPatternReverse(TestCase): else: 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): urls = 'regressiontests.urlpatterns_reverse.urls'