Fixed #27063 -- Prevented i18n_patterns() from using too much of the URL as the language.
This commit is contained in:
parent
ee06689878
commit
a01d887a3a
|
@ -45,7 +45,7 @@ language_code_re = re.compile(
|
|||
re.IGNORECASE
|
||||
)
|
||||
|
||||
language_code_prefix_re = re.compile(r'^/([\w@-]+)(/|$)')
|
||||
language_code_prefix_re = re.compile(r'^/(\w+([@-]\w+)?)(/|$)')
|
||||
|
||||
|
||||
@receiver(setting_changed)
|
||||
|
|
|
@ -23,3 +23,6 @@ Bugfixes
|
|||
|
||||
* Fixed ``QuerySet.bulk_create()`` on PostgreSQL when the number of objects is
|
||||
a multiple plus one of ``batch_size`` (:ticket:`27385`).
|
||||
|
||||
* Prevented ``i18n_patterns()`` from using too much of the URL as the language
|
||||
to fix a use case for ``prefix_default_language=False`` (:ticket:`27063`).
|
||||
|
|
|
@ -1490,6 +1490,7 @@ class MiscTests(SimpleTestCase):
|
|||
self.assertEqual(g('/de/'), 'de')
|
||||
self.assertEqual(g('/de-at/'), 'de-at')
|
||||
self.assertEqual(g('/de-ch/'), 'de')
|
||||
self.assertIsNone(g('/de-simple-page/'))
|
||||
|
||||
def test_get_language_from_path_null(self):
|
||||
from django.utils.translation.trans_null import get_language_from_path as g
|
||||
|
@ -1822,6 +1823,7 @@ class LocaleMiddlewareTests(TestCase):
|
|||
USE_I18N=True,
|
||||
LANGUAGES=[
|
||||
('en', 'English'),
|
||||
('de', 'German'),
|
||||
('fr', 'French'),
|
||||
],
|
||||
MIDDLEWARE=[
|
||||
|
@ -1852,6 +1854,11 @@ class UnprefixedDefaultLanguageTests(SimpleTestCase):
|
|||
with self.assertRaisesMessage(AssertionError, "Unexpected kwargs for i18n_patterns(): {'foo':"):
|
||||
i18n_patterns(object(), foo='bar')
|
||||
|
||||
def test_page_with_dash(self):
|
||||
# A page starting with /de* shouldn't match the 'de' langauge code.
|
||||
response = self.client.get('/de-simple-page/')
|
||||
self.assertEqual(response.content, b'Yes')
|
||||
|
||||
|
||||
@override_settings(
|
||||
USE_I18N=True,
|
||||
|
|
|
@ -4,6 +4,7 @@ from django.http import HttpResponse
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
urlpatterns = i18n_patterns(
|
||||
url(r'^(?P<arg>[\w-]+)-page', lambda request, **arg: HttpResponse(_("Yes"))),
|
||||
url(r'^simple/$', lambda r: HttpResponse(_("Yes"))),
|
||||
prefix_default_language=False,
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue