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
|
re.IGNORECASE
|
||||||
)
|
)
|
||||||
|
|
||||||
language_code_prefix_re = re.compile(r'^/([\w@-]+)(/|$)')
|
language_code_prefix_re = re.compile(r'^/(\w+([@-]\w+)?)(/|$)')
|
||||||
|
|
||||||
|
|
||||||
@receiver(setting_changed)
|
@receiver(setting_changed)
|
||||||
|
|
|
@ -23,3 +23,6 @@ Bugfixes
|
||||||
|
|
||||||
* Fixed ``QuerySet.bulk_create()`` on PostgreSQL when the number of objects is
|
* Fixed ``QuerySet.bulk_create()`` on PostgreSQL when the number of objects is
|
||||||
a multiple plus one of ``batch_size`` (:ticket:`27385`).
|
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/'), 'de')
|
||||||
self.assertEqual(g('/de-at/'), 'de-at')
|
self.assertEqual(g('/de-at/'), 'de-at')
|
||||||
self.assertEqual(g('/de-ch/'), 'de')
|
self.assertEqual(g('/de-ch/'), 'de')
|
||||||
|
self.assertIsNone(g('/de-simple-page/'))
|
||||||
|
|
||||||
def test_get_language_from_path_null(self):
|
def test_get_language_from_path_null(self):
|
||||||
from django.utils.translation.trans_null import get_language_from_path as g
|
from django.utils.translation.trans_null import get_language_from_path as g
|
||||||
|
@ -1822,6 +1823,7 @@ class LocaleMiddlewareTests(TestCase):
|
||||||
USE_I18N=True,
|
USE_I18N=True,
|
||||||
LANGUAGES=[
|
LANGUAGES=[
|
||||||
('en', 'English'),
|
('en', 'English'),
|
||||||
|
('de', 'German'),
|
||||||
('fr', 'French'),
|
('fr', 'French'),
|
||||||
],
|
],
|
||||||
MIDDLEWARE=[
|
MIDDLEWARE=[
|
||||||
|
@ -1852,6 +1854,11 @@ class UnprefixedDefaultLanguageTests(SimpleTestCase):
|
||||||
with self.assertRaisesMessage(AssertionError, "Unexpected kwargs for i18n_patterns(): {'foo':"):
|
with self.assertRaisesMessage(AssertionError, "Unexpected kwargs for i18n_patterns(): {'foo':"):
|
||||||
i18n_patterns(object(), foo='bar')
|
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(
|
@override_settings(
|
||||||
USE_I18N=True,
|
USE_I18N=True,
|
||||||
|
|
|
@ -4,6 +4,7 @@ from django.http import HttpResponse
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
urlpatterns = i18n_patterns(
|
urlpatterns = i18n_patterns(
|
||||||
|
url(r'^(?P<arg>[\w-]+)-page', lambda request, **arg: HttpResponse(_("Yes"))),
|
||||||
url(r'^simple/$', lambda r: HttpResponse(_("Yes"))),
|
url(r'^simple/$', lambda r: HttpResponse(_("Yes"))),
|
||||||
prefix_default_language=False,
|
prefix_default_language=False,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue