From 05c578bc1f6ab09ade17a29f79d7244b7acfb58f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pawe=C5=82=20Ko=C5=82odziej?=
Date: Fri, 28 Sep 2018 01:49:37 +0200
Subject: [PATCH] Fixed #29796 -- Added system check for STATICFILES_DIRS
prefix ending with a slash.
---
django/contrib/staticfiles/finders.py | 8 +++++++-
docs/ref/checks.txt | 2 ++
tests/staticfiles_tests/test_checks.py | 10 ++++++++++
3 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/django/contrib/staticfiles/finders.py b/django/contrib/staticfiles/finders.py
index afce4ca637..8d8f1cb983 100644
--- a/django/contrib/staticfiles/finders.py
+++ b/django/contrib/staticfiles/finders.py
@@ -78,7 +78,13 @@ class FileSystemFinder(BaseFinder):
))
for root in settings.STATICFILES_DIRS:
if isinstance(root, (list, tuple)):
- _, root = root
+ prefix, root = root
+ if prefix.endswith('/'):
+ errors.append(Error(
+ 'The prefix %r in the STATICFILES_DIRS setting must '
+ 'not end with a slash.' % prefix,
+ id='staticfiles.E003',
+ ))
if settings.STATIC_ROOT and os.path.abspath(settings.STATIC_ROOT) == os.path.abspath(root):
errors.append(Error(
'The STATICFILES_DIRS setting should not contain the '
diff --git a/docs/ref/checks.txt b/docs/ref/checks.txt
index 6895a93eff..67813067f2 100644
--- a/docs/ref/checks.txt
+++ b/docs/ref/checks.txt
@@ -731,3 +731,5 @@ configured:
or list.
* **staticfiles.E002**: The :setting:`STATICFILES_DIRS` setting should not
contain the :setting:`STATIC_ROOT` setting.
+* **staticfiles.E003**: The prefix ```` in the
+ :setting:`STATICFILES_DIRS` setting must not end with a slash.
diff --git a/tests/staticfiles_tests/test_checks.py b/tests/staticfiles_tests/test_checks.py
index 0fe432b5c7..d5dc90b781 100644
--- a/tests/staticfiles_tests/test_checks.py
+++ b/tests/staticfiles_tests/test_checks.py
@@ -75,3 +75,13 @@ class FindersCheckTests(SimpleTestCase):
id='staticfiles.E002',
)
])
+
+ @override_settings(STATICFILES_DIRS=[('prefix/', '/fake/path')])
+ def test_prefix_contains_trailing_slash(self):
+ self.assertEqual(check_finders(None), [
+ Error(
+ "The prefix 'prefix/' in the STATICFILES_DIRS setting must "
+ "not end with a slash.",
+ id='staticfiles.E003',
+ )
+ ])