summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlton Gibson <carlton.gibson@noumenal.es>2021-11-04 10:20:04 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-11-04 21:41:25 +0100
commit499384b6d1a0082d538470d57ade37591e9251d6 (patch)
treeeceaa932072c5f8bfec6b902e9a356ce65e1935c
parent6fc689a22d2d8bc84b2c407132af5d2cb2cf0673 (diff)
[4.0.x] Fixed #33237 -- Fixed detecting source maps in ManifestStaticFilesStorage for multiline files.
Switched regex to multiline mode in order to match per-line, rather than against the whole file. Thanks to Joseph Abrahams for the report. Regression in 781b44240a06f0c868254f40f36ce46c927f56d1. Backport of 4816dc942860caf076c7c85ea9dbfa8bfab212ff from main
-rw-r--r--django/contrib/staticfiles/storage.py2
-rw-r--r--tests/staticfiles_tests/project/documents/cached/source_map.js1
-rw-r--r--tests/staticfiles_tests/test_storage.py2
3 files changed, 3 insertions, 2 deletions
diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py
index 7cf43ed6ab..bb66304a7e 100644
--- a/django/contrib/staticfiles/storage.py
+++ b/django/contrib/staticfiles/storage.py
@@ -54,7 +54,7 @@ class HashedFilesMixin:
)),
('*.js', (
(
- r'(?P<matched>)^(//# (?-i:sourceMappingURL)=(?P<url>.*))$',
+ r'(?m)(?P<matched>)^(//# (?-i:sourceMappingURL)=(?P<url>.*))$',
'//# sourceMappingURL=%(url)s',
),
(
diff --git a/tests/staticfiles_tests/project/documents/cached/source_map.js b/tests/staticfiles_tests/project/documents/cached/source_map.js
index b37c5e5701..9d417868a0 100644
--- a/tests/staticfiles_tests/project/documents/cached/source_map.js
+++ b/tests/staticfiles_tests/project/documents/cached/source_map.js
@@ -1 +1,2 @@
//# sourceMappingURL=source_map.js.map
+let a_variable = 1;
diff --git a/tests/staticfiles_tests/test_storage.py b/tests/staticfiles_tests/test_storage.py
index 0a34f64394..93335480be 100644
--- a/tests/staticfiles_tests/test_storage.py
+++ b/tests/staticfiles_tests/test_storage.py
@@ -260,7 +260,7 @@ class TestHashedFiles:
def test_js_source_map(self):
relpath = self.hashed_file_path('cached/source_map.js')
- self.assertEqual(relpath, 'cached/source_map.9371cbb02a26.js')
+ self.assertEqual(relpath, 'cached/source_map.cd45b8534a87.js')
with storage.staticfiles_storage.open(relpath) as relfile:
content = relfile.read()
self.assertNotIn(b'//# sourceMappingURL=source_map.js.map', content)