Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #10834 -- Added bucket condition to ensure that URL resolvers w…

…on'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
  • Loading branch information...
commit 735309341e24d53d5af41799a31aa964f424190c 1 parent e522e61
Russell Keith-Magee authored June 29, 2009
1  django/core/urlresolvers.py
@@ -195,6 +195,7 @@ def resolve(self, path):
195 195
                         return sub_match[0], sub_match[1], sub_match_dict
196 196
                     tried.append(pattern.regex.pattern)
197 197
             raise Resolver404, {'tried': tried, 'path': new_path}
  198
+        raise Resolver404, {'tried': [], 'path' : path}
198 199
 
199 200
     def _get_urlconf_module(self):
200 201
         try:
18  tests/regressiontests/urlpatterns_reverse/tests.py
@@ -14,8 +14,9 @@
14 14
 ImproperlyConfigured: The included urlconf regressiontests.urlpatterns_reverse.no_urls doesn't have any patterns in it
15 15
 """}
16 16
 
  17
+import unittest
17 18
 
18  
-from django.core.urlresolvers import reverse, NoReverseMatch
  19
+from django.core.urlresolvers import reverse, resolve, NoReverseMatch, Resolver404
19 20
 from django.http import HttpResponseRedirect, HttpResponsePermanentRedirect
20 21
 from django.shortcuts import redirect
21 22
 from django.test import TestCase
@@ -112,6 +113,21 @@ def test_urlpattern_reverse(self):
112 113
             else:
113 114
                 self.assertEquals(got, expected)
114 115
 
  116
+class ResolverTests(unittest.TestCase):
  117
+    def test_non_regex(self):
  118
+        """
  119
+        Verifies that we raise a Resolver404 if what we are resolving doesn't
  120
+        meet the basic requirements of a path to match - i.e., at the very
  121
+        least, it matches the root pattern '^/'. We must never return None
  122
+        from resolve, or we will get a TypeError further down the line.
  123
+
  124
+        Regression for #10834.
  125
+        """
  126
+        self.assertRaises(Resolver404, resolve, '')
  127
+        self.assertRaises(Resolver404, resolve, 'a')
  128
+        self.assertRaises(Resolver404, resolve, '\\')
  129
+        self.assertRaises(Resolver404, resolve, '.')
  130
+
115 131
 class ReverseShortcutTests(TestCase):
116 132
     urls = 'regressiontests.urlpatterns_reverse.urls'
117 133
 

0 notes on commit 7353093

Please sign in to comment.
Something went wrong with that request. Please try again.