summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Apolloner <florian@apolloner.eu>2022-05-10 17:10:04 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-06-23 08:59:49 +0200
commite6f36ea0a97af5c7d18bd155a6c4a937cf658ce6 (patch)
tree485e524246923c7d4b01d2b731a686b3065a075d
parentd80a2585532ef15184afed6cf4ec1358198a894d (diff)
Made HashedFilesMixin ignore URLs without a path.
-rw-r--r--django/contrib/staticfiles/storage.py4
-rw-r--r--tests/staticfiles_tests/project/documents/cached/css/ignored.css1
-rw-r--r--tests/staticfiles_tests/test_storage.py3
3 files changed, 7 insertions, 1 deletions
diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py
index d62cbb6e68..5c0159c0b4 100644
--- a/django/contrib/staticfiles/storage.py
+++ b/django/contrib/staticfiles/storage.py
@@ -202,6 +202,10 @@ class HashedFilesMixin:
# Strip off the fragment so a path-like fragment won't interfere.
url_path, fragment = urldefrag(url)
+ # Ignore URLs without a path
+ if not url_path:
+ return matched
+
if url_path.startswith("/"):
# Otherwise the condition above would have returned prematurely.
assert url_path.startswith(settings.STATIC_URL)
diff --git a/tests/staticfiles_tests/project/documents/cached/css/ignored.css b/tests/staticfiles_tests/project/documents/cached/css/ignored.css
index 83b1d5ebf8..70a8cb918a 100644
--- a/tests/staticfiles_tests/project/documents/cached/css/ignored.css
+++ b/tests/staticfiles_tests/project/documents/cached/css/ignored.css
@@ -5,5 +5,6 @@ body {
background: url("data:foobar");
background: url("chrome:foobar");
background: url("//foobar");
+ background: url();
}
diff --git a/tests/staticfiles_tests/test_storage.py b/tests/staticfiles_tests/test_storage.py
index 745094acf6..16bb556d4f 100644
--- a/tests/staticfiles_tests/test_storage.py
+++ b/tests/staticfiles_tests/test_storage.py
@@ -65,7 +65,7 @@ class TestHashedFiles:
def test_path_ignored_completely(self):
relpath = self.hashed_file_path("cached/css/ignored.css")
- self.assertEqual(relpath, "cached/css/ignored.554da52152af.css")
+ self.assertEqual(relpath, "cached/css/ignored.55e7c226dda1.css")
with storage.staticfiles_storage.open(relpath) as relfile:
content = relfile.read()
self.assertIn(b"#foobar", content)
@@ -74,6 +74,7 @@ class TestHashedFiles:
self.assertIn(b"data:foobar", content)
self.assertIn(b"chrome:foobar", content)
self.assertIn(b"//foobar", content)
+ self.assertIn(b"url()", content)
self.assertPostCondition()
def test_path_with_querystring(self):