Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#33237 closed Bug (fixed)

ManifestStaticFilesStorage doesn't update JavaScript source map references in multiline files

Reported by: Joseph Abrahams Owned by: Carlton Gibson
Component: contrib.staticfiles Version: 4.0
Severity: Release blocker Keywords:
Cc: Adam Johnson, gilmrjc Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Current implementation of HashedFilesMixin relies on regex multiline mode to parse out the sourceMappingURL comment. As is, the filename is only correctly replaced when the comment is the first and only line in the JS file (exception to final single new line at EOF).

Steps to reproduce:

  • Include static multi-line javascript file that contains a valid sourceMappingURL comment in a project with STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'
  • Run python manage.py collectstatic
  • Open the new hashed javascript file and observe the unmodified sourceMappingURL comment

See updated, failing test case: https://joseph.is/3CrvpSW.

More than happy to work on a patch provided some guidance on expected functionality.

Change History (6)

comment:1 by Mariusz Felisiak, 3 years ago

Cc: Adam Johnson added
Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

Thanks for the report, it's a bug in a new feature introduced in e32722d1606794f0a85d74811e53a0336a1ce305 (see #32383).

comment:2 by Carlton Gibson, 3 years ago

Has patch: set
Owner: changed from nobody to Carlton Gibson
Status: newassigned

PR switching the regex to multiline mode.

Joseph, if you're able to have a look, that would be great.

comment:3 by Carlton Gibson, 3 years ago

Cc: gilmrjc added

Looks like the regression was introduced in 781b44240a06f0c868254f40f36ce46c927f56d1 as part of #32319.
(The multiline flag was removed switching to named groups.)

comment:4 by Mariusz Felisiak, 3 years ago

Triage Stage: AcceptedReady for checkin

comment:5 by Mariusz Felisiak <felisiak.mariusz@…>, 3 years ago

Resolution: fixed
Status: assignedclosed

In 4816dc9:

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.

comment:6 by Mariusz Felisiak <felisiak.mariusz@…>, 3 years ago

In 499384b:

[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

Note: See TracTickets for help on using tickets.
Back to Top