summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Cormier-Iijima <samuel@cormier-iijima.com>2025-04-22 22:00:20 -0400
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2025-05-16 15:56:17 +0200
commit1ba5fe19ca221663e6a1e9391dbe726bb2baaf8a (patch)
tree9af3766da65f16dfde72d8811229c544fa2570fc
parent994dc6d8a1bae717baa236b65e11cf91ce181c53 (diff)
Fixed #36348 -- Fixed handling multiple nested url()s in ManifestStaticFilesStorage.
Signed-off-by: Samuel Cormier-Iijima <samuel@cormier-iijima.com>
-rw-r--r--django/contrib/staticfiles/storage.py3
-rw-r--r--tests/staticfiles_tests/project/documents/cached/data_uri_with_nested_url.css3
-rw-r--r--tests/staticfiles_tests/test_storage.py7
3 files changed, 12 insertions, 1 deletions
diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py
index dfc3137f76..95e71e45fc 100644
--- a/django/contrib/staticfiles/storage.py
+++ b/django/contrib/staticfiles/storage.py
@@ -80,7 +80,8 @@ class HashedFilesMixin:
(
"*.css",
(
- r"""(?P<matched>url\(['"]{0,1}\s*(?P<url>.*?)["']{0,1}\))""",
+ r"""(?P<matched>url\((?P<quote>['"]{0,1})"""
+ r"""\s*(?P<url>.*?)(?P=quote)\))""",
(
r"""(?P<matched>@import\s*["']\s*(?P<url>.*?)["'])""",
"""@import url("%(url)s")""",
diff --git a/tests/staticfiles_tests/project/documents/cached/data_uri_with_nested_url.css b/tests/staticfiles_tests/project/documents/cached/data_uri_with_nested_url.css
new file mode 100644
index 0000000000..86e64e9498
--- /dev/null
+++ b/tests/staticfiles_tests/project/documents/cached/data_uri_with_nested_url.css
@@ -0,0 +1,3 @@
+#example {
+ background-image: url("data:image/svg+xml,url(%23b) url(%23c)");
+}
diff --git a/tests/staticfiles_tests/test_storage.py b/tests/staticfiles_tests/test_storage.py
index 9ca4d62553..35799f0ff7 100644
--- a/tests/staticfiles_tests/test_storage.py
+++ b/tests/staticfiles_tests/test_storage.py
@@ -235,6 +235,13 @@ class TestHashedFiles:
self.assertIn(b"other.d41d8cd98f00.css", content)
self.assertPostCondition()
+ def test_css_data_uri_with_nested_url(self):
+ relpath = self.hashed_file_path("cached/data_uri_with_nested_url.css")
+ with storage.staticfiles_storage.open(relpath) as relfile:
+ content = relfile.read()
+ self.assertIn(b'url("data:image/svg+xml,url(%23b) url(%23c)")', content)
+ self.assertPostCondition()
+
def test_css_source_map(self):
relpath = self.hashed_file_path("cached/source_map.css")
self.assertEqual(relpath, "cached/source_map.b2fceaf426aa.css")