Ticket #6170: 6170.diff

File 6170.diff, 2.2 KB (added by David Gouldin, 12 years ago)
  • django/core/urlresolvers.py

    diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py
    index 625ec63..58213a3 100644
    a b class LocaleRegexProvider(object):  
    160160        language_code = get_language()
    161161        if language_code not in self._regex_dict:
    162162            if isinstance(self._regex, basestring):
    163                 compiled_regex = re.compile(self._regex, re.UNICODE)
     163                regex = self._regex
    164164            else:
    165165                regex = force_unicode(self._regex)
     166            try:
    166167                compiled_regex = re.compile(regex, re.UNICODE)
     168            except re.error, e:
     169                raise ImproperlyConfigured(
     170                    u'"%s" is not a valid regular expression: %s' %
     171                    (regex, unicode(e)))
     172
    167173            self._regex_dict[language_code] = compiled_regex
    168174        return self._regex_dict[language_code]
    169175
  • tests/regressiontests/urlpatterns_reverse/erroneous_urls.py

    diff --git a/tests/regressiontests/urlpatterns_reverse/erroneous_urls.py b/tests/regressiontests/urlpatterns_reverse/erroneous_urls.py
    index 8e6433e..e1ef5b2 100644
    a b urlpatterns = patterns('',  
    1111    url(r'uncallable/$', 'regressiontests.urlpatterns_reverse.views.uncallable'),
    1212    # Module does not exist
    1313    url(r'missing_outer/$', 'regressiontests.urlpatterns_reverse.missing_module.missing_view'),
     14    # Regex contains an error
     15    url(r'(regex_error/$', 'regressiontestes.urlpatterns_reverse.views.empty_view'),
    1416)
  • tests/regressiontests/urlpatterns_reverse/tests.py

    diff --git a/tests/regressiontests/urlpatterns_reverse/tests.py b/tests/regressiontests/urlpatterns_reverse/tests.py
    index bb25806..eeb83de 100644
    a b class ErroneousViewTests(TestCase):  
    511511        self.assertRaises(ViewDoesNotExist, self.client.get, '/missing_outer/')
    512512        self.assertRaises(ViewDoesNotExist, self.client.get, '/uncallable/')
    513513
     514    def test_erroneous_reverse(self):
     515        # The regex error will be hit before NoReverseMatch can be raised
     516        self.assertRaises(ImproperlyConfigured, reverse, 'asdf')
     517
Back to Top