summaryrefslogtreecommitdiff
path: root/tests/staticfiles_tests
diff options
context:
space:
mode:
authorHielke Walinga <hielkewalinga@gmail.com>2023-04-17 14:30:10 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-04-21 05:42:06 +0200
commitfb535e0a9033bd58d4bcb31876508e895c9b866d (patch)
treed0c98f5203fbddedb1bf125774aba451c532278d /tests/staticfiles_tests
parent498195bda492d09ed00d05ab268cad4b8e5c9f21 (diff)
downloaddjango-fb535e0a9033bd58d4bcb31876508e895c9b866d.tar.gz
Fixed #34496 -- Fixed handling source maps with data URI in ManifestStaticFilesStorage.
Regression in 781b44240a06f0c868254f40f36ce46c927f56d1.
Diffstat (limited to 'tests/staticfiles_tests')
-rw-r--r--tests/staticfiles_tests/project/documents/cached/source_map_data_uri.css2
-rw-r--r--tests/staticfiles_tests/project/documents/cached/source_map_data_uri.js2
-rw-r--r--tests/staticfiles_tests/test_storage.py24
3 files changed, 28 insertions, 0 deletions
diff --git a/tests/staticfiles_tests/project/documents/cached/source_map_data_uri.css b/tests/staticfiles_tests/project/documents/cached/source_map_data_uri.css
new file mode 100644
index 0000000000..7b6bc63241
--- /dev/null
+++ b/tests/staticfiles_tests/project/documents/cached/source_map_data_uri.css
@@ -0,0 +1,2 @@
+* {outline: 1px solid red;}
+/*# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIl9zcmMv*/
diff --git a/tests/staticfiles_tests/project/documents/cached/source_map_data_uri.js b/tests/staticfiles_tests/project/documents/cached/source_map_data_uri.js
new file mode 100644
index 0000000000..316fb1fecd
--- /dev/null
+++ b/tests/staticfiles_tests/project/documents/cached/source_map_data_uri.js
@@ -0,0 +1,2 @@
+//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIl9zcmMv
+let a_variable = 1;
diff --git a/tests/staticfiles_tests/test_storage.py b/tests/staticfiles_tests/test_storage.py
index 2202a5bc07..dc8607a307 100644
--- a/tests/staticfiles_tests/test_storage.py
+++ b/tests/staticfiles_tests/test_storage.py
@@ -269,6 +269,18 @@ class TestHashedFiles:
)
self.assertPostCondition()
+ def test_css_source_map_data_uri(self):
+ relpath = self.hashed_file_path("cached/source_map_data_uri.css")
+ self.assertEqual(relpath, "cached/source_map_data_uri.3166be10260d.css")
+ with storage.staticfiles_storage.open(relpath) as relfile:
+ content = relfile.read()
+ source_map_data_uri = (
+ b"/*# sourceMappingURL=data:application/json;charset=utf8;base64,"
+ b"eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIl9zcmMv*/"
+ )
+ self.assertIn(source_map_data_uri, content)
+ self.assertPostCondition()
+
def test_js_source_map(self):
relpath = self.hashed_file_path("cached/source_map.js")
self.assertEqual(relpath, "cached/source_map.cd45b8534a87.js")
@@ -307,6 +319,18 @@ class TestHashedFiles:
)
self.assertPostCondition()
+ def test_js_source_map_data_uri(self):
+ relpath = self.hashed_file_path("cached/source_map_data_uri.js")
+ self.assertEqual(relpath, "cached/source_map_data_uri.a68d23cbf6dd.js")
+ with storage.staticfiles_storage.open(relpath) as relfile:
+ content = relfile.read()
+ source_map_data_uri = (
+ b"//# sourceMappingURL=data:application/json;charset=utf8;base64,"
+ b"eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIl9zcmMv"
+ )
+ self.assertIn(source_map_data_uri, content)
+ self.assertPostCondition()
+
@override_settings(
STATICFILES_DIRS=[os.path.join(TEST_ROOT, "project", "faulty")],
STATICFILES_FINDERS=["django.contrib.staticfiles.finders.FileSystemFinder"],