Fixed #26271 -- Fixed i18n_patterns resolution when no language is active

Thanks Marten Kenbeek for the report.
This commit is contained in:
Claude Paroz 2016-03-05 20:20:40 +01:00
parent 2109975e90
commit 95ca01f999
2 changed files with 5 additions and 1 deletions

View File

@ -11,6 +11,7 @@ import functools
import re
from importlib import import_module
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.utils import lru_cache, six
from django.utils.datastructures import MultiValueDict
@ -388,7 +389,7 @@ class LocaleRegexURLResolver(RegexURLResolver):
@property
def regex(self):
language_code = get_language()
language_code = get_language() or settings.LANGUAGE_CODE
if language_code not in self._regex_dict:
regex_compiled = re.compile('^%s/' % language_code, re.UNICODE)
self._regex_dict[language_code] = regex_compiled

View File

@ -2,6 +2,7 @@ from __future__ import unicode_literals
import os
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.http import HttpResponsePermanentRedirect
from django.middleware.locale import LocaleMiddleware
@ -75,6 +76,8 @@ class URLPrefixTests(URLTestCaseBase):
self.assertEqual(reverse('prefixed'), '/en/prefixed/')
with translation.override('nl'):
self.assertEqual(reverse('prefixed'), '/nl/prefixed/')
with translation.override(None):
self.assertEqual(reverse('prefixed'), '/%s/prefixed/' % settings.LANGUAGE_CODE)
@override_settings(ROOT_URLCONF='i18n.patterns.urls.wrong')
def test_invalid_prefix_use(self):