From b811364421c8eea0cf06459462cf1fd58184773b Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Thu, 3 Mar 2022 17:28:57 +0000 Subject: [PATCH] Refs #33446 -- Allowed variable whitespace in CSS source map references. Follow up to dc8bb35e39388d41b1f38b6c5d0181224e075f16. The Webpack default is to output CSS source map comments like `/*# sourceMappingURL=main.css.map*/`. Also, Chromium allows tabs. --- django/contrib/staticfiles/storage.py | 5 ++++- .../project/documents/cached/source_map.css | 2 +- .../project/documents/cached/source_map_tabs.css | 2 ++ tests/staticfiles_tests/test_storage.py | 14 +++++++++++++- 4 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 tests/staticfiles_tests/project/documents/cached/source_map_tabs.css diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py index 754f173263..d62cbb6e68 100644 --- a/django/contrib/staticfiles/storage.py +++ b/django/contrib/staticfiles/storage.py @@ -57,7 +57,10 @@ class HashedFilesMixin: """@import url("%(url)s")""", ), ( - r"(?m)(?P)^(/\*# (?-i:sourceMappingURL)=(?P.*) \*/)$", + ( + r"(?m)(?P)^(/\*#[ \t]" + r"(?-i:sourceMappingURL)=(?P.*)[ \t]*\*/)$" + ), "/*# sourceMappingURL=%(url)s */", ), ), diff --git a/tests/staticfiles_tests/project/documents/cached/source_map.css b/tests/staticfiles_tests/project/documents/cached/source_map.css index dcd65da596..a07d612403 100644 --- a/tests/staticfiles_tests/project/documents/cached/source_map.css +++ b/tests/staticfiles_tests/project/documents/cached/source_map.css @@ -1,2 +1,2 @@ * {outline: 1px solid red;} -/*# sourceMappingURL=source_map.css.map */ +/*# sourceMappingURL=source_map.css.map*/ diff --git a/tests/staticfiles_tests/project/documents/cached/source_map_tabs.css b/tests/staticfiles_tests/project/documents/cached/source_map_tabs.css new file mode 100644 index 0000000000..3ae2073dc8 --- /dev/null +++ b/tests/staticfiles_tests/project/documents/cached/source_map_tabs.css @@ -0,0 +1,2 @@ +* {outline: 1px solid red;} +/*# sourceMappingURL=source_map.css.map */ diff --git a/tests/staticfiles_tests/test_storage.py b/tests/staticfiles_tests/test_storage.py index 38c34c3f66..3783d32872 100644 --- a/tests/staticfiles_tests/test_storage.py +++ b/tests/staticfiles_tests/test_storage.py @@ -237,7 +237,19 @@ class TestHashedFiles: self.assertEqual(relpath, "cached/source_map.b2fceaf426aa.css") with storage.staticfiles_storage.open(relpath) as relfile: content = relfile.read() - self.assertNotIn(b"/*# sourceMappingURL=source_map.css.map */", content) + self.assertNotIn(b"/*# sourceMappingURL=source_map.css.map*/", content) + self.assertIn( + b"/*# sourceMappingURL=source_map.css.99914b932bd3.map */", + content, + ) + self.assertPostCondition() + + def test_css_source_map_tabs(self): + relpath = self.hashed_file_path("cached/source_map_tabs.css") + self.assertEqual(relpath, "cached/source_map_tabs.b2fceaf426aa.css") + with storage.staticfiles_storage.open(relpath) as relfile: + content = relfile.read() + self.assertNotIn(b"/*#\tsourceMappingURL=source_map.css.map\t*/", content) self.assertIn( b"/*# sourceMappingURL=source_map.css.99914b932bd3.map */", content,