summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2017-04-02 20:14:39 +0200
committerClaude Paroz <claude@2xlibre.net>2017-06-06 18:02:22 +0200
commit23142eea85c66bfd2cdade016054ed162ea0fa63 (patch)
tree1db7f5e2c66d6532beba3af276b082a9ad63bb62
parent41e02ab368af3e64f82a568880cbc8fb0bc527f6 (diff)
Fixed #18394 -- Added error for invalid JavaScriptCatalog packages
Thanks Tim Graham for the review.
-rw-r--r--django/views/i18n.py5
-rw-r--r--docs/releases/2.0.txt4
-rw-r--r--tests/view_tests/tests/test_i18n.py15
3 files changed, 22 insertions, 2 deletions
diff --git a/django/views/i18n.py b/django/views/i18n.py
index 9edf83e857..9a16a78368 100644
--- a/django/views/i18n.py
+++ b/django/views/i18n.py
@@ -232,6 +232,11 @@ class JavaScriptCatalog(View):
def get_paths(self, packages):
allowable_packages = {app_config.name: app_config for app_config in apps.get_app_configs()}
app_configs = [allowable_packages[p] for p in packages if p in allowable_packages]
+ if len(app_configs) < len(packages):
+ excluded = [p for p in packages if p not in allowable_packages]
+ raise ValueError(
+ 'Invalid package(s) provided to JavaScriptCatalog: %s' % ','.join(excluded)
+ )
# paths of requested packages
return [os.path.join(app.path, 'locale') for app in app_configs]
diff --git a/docs/releases/2.0.txt b/docs/releases/2.0.txt
index 32f7413331..fef59ba880 100644
--- a/docs/releases/2.0.txt
+++ b/docs/releases/2.0.txt
@@ -420,6 +420,10 @@ Miscellaneous
Book.objects.iterator(chunk_size=100)
+* Providing unknown package names in the ``packages`` argument of the
+ :class:`~django.views.i18n.JavaScriptCatalog` view now raises ``ValueError``
+ instead of passing silently.
+
.. _deprecated-features-2.0:
Features deprecated in 2.0
diff --git a/tests/view_tests/tests/test_i18n.py b/tests/view_tests/tests/test_i18n.py
index c4d9a9a986..38e5367d03 100644
--- a/tests/view_tests/tests/test_i18n.py
+++ b/tests/view_tests/tests/test_i18n.py
@@ -4,14 +4,15 @@ from os import path
from django.conf import settings
from django.test import (
- SimpleTestCase, TestCase, modify_settings, override_settings,
+ RequestFactory, SimpleTestCase, TestCase, modify_settings,
+ override_settings,
)
from django.test.selenium import SeleniumTestCase
from django.urls import reverse
from django.utils.translation import (
LANGUAGE_SESSION_KEY, get_language, override,
)
-from django.views.i18n import get_formats
+from django.views.i18n import JavaScriptCatalog, get_formats
from ..urls import locale_dir
@@ -397,6 +398,16 @@ class I18NViewTests(SimpleTestCase):
response = self.client.get('/jsi18n/')
self.assertContains(response, 'este texto de app3 debe ser traducido')
+ def test_i18n_unknown_package_error(self):
+ view = JavaScriptCatalog.as_view()
+ request = RequestFactory().get('/')
+ msg = 'Invalid package(s) provided to JavaScriptCatalog: unknown_package'
+ with self.assertRaisesMessage(ValueError, msg):
+ view(request, packages='unknown_package')
+ msg += ',unknown_package2'
+ with self.assertRaisesMessage(ValueError, msg):
+ view(request, packages='unknown_package+unknown_package2')
+
@override_settings(ROOT_URLCONF='view_tests.urls')
class I18nSeleniumTests(SeleniumTestCase):