[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 781b44240a.

Backport of 4816dc9428 from main
This commit is contained in:
Carlton Gibson 2021-11-04 10:20:04 +01:00 committed by Mariusz Felisiak
parent 6fc689a22d
commit 499384b6d1
3 changed files with 3 additions and 2 deletions

View File

@ -54,7 +54,7 @@ class HashedFilesMixin:
)), )),
('*.js', ( ('*.js', (
( (
r'(?P<matched>)^(//# (?-i:sourceMappingURL)=(?P<url>.*))$', r'(?m)(?P<matched>)^(//# (?-i:sourceMappingURL)=(?P<url>.*))$',
'//# sourceMappingURL=%(url)s', '//# sourceMappingURL=%(url)s',
), ),
( (

View File

@ -1 +1,2 @@
//# sourceMappingURL=source_map.js.map //# sourceMappingURL=source_map.js.map
let a_variable = 1;

View File

@ -260,7 +260,7 @@ class TestHashedFiles:
def test_js_source_map(self): def test_js_source_map(self):
relpath = self.hashed_file_path('cached/source_map.js') 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: with storage.staticfiles_storage.open(relpath) as relfile:
content = relfile.read() content = relfile.read()
self.assertNotIn(b'//# sourceMappingURL=source_map.js.map', content) self.assertNotIn(b'//# sourceMappingURL=source_map.js.map', content)