#22972: HashedFilesMixin
-------------------------+-------------------------------------------------
Reporter: | Owner: nobody
alex.ehlke@… | Status: new
Type: | Version: 1.7-rc-1
Uncategorized | Keywords: HashedFilesMixin CachedFilesMixin
Component: | staticfiles
contrib.staticfiles | Has patch: 0
Severity: Normal | UI/UX: 0
Triage Stage: |
Unreviewed |
Easy pickings: 0 |
-------------------------+-------------------------------------------------
{{{HashedFilesMixin}}} contains a {{{patterns}}} property which maps file
extensions to regex patterns. This works great for the default case that
Django ships with {{{"*.css"}}} as the only filetype, but results in
surprising behavior once extended with multiple filetypes. I would expect
the regex patterns to only apply to the filetype they're categorized
under, but once I added {{{"*.js"}}} to {{{patterns}}} (via subclassing),
the CSS rules also applied to my JS files.
My use-case of extending this is to add URL rewriting to JS source map
references, e.g. {{{//# sourceMappingURL=foo.js.map }}} which can appear
at the end of JS files. I need to be able to rewrite these URLs in the
same way that Django's staticfiles can rewrite URLs in CSS, for e.g.
adding hashes to filenames.
Once I tried extending {{{patterns}}} with this:
{{{
patterns = HashedFilesMixin.patterns + (
("*.js", (
(r"""(//# sourceMappingURL=(\s*))""", """//#
sourceMappingURL=%s"""),
)),
)
}}}
The surprising and broken behavior was that Django tried to rewrite "URLs"
for this JS (from Backbone.js): {{{this.loadUrl(window.location.hash)}}},
which matched the CSS pattern for rewriting {{{url(foo)}}} because the
regex patterns are case-insensitive.
This also applies to the previous {{{CachedFilesMixin}}} from before 1.7.
Please let me know if a fix for this would be accepted, and I'll put
together a test case and patch.
--
Ticket URL: <https://code.djangoproject.com/ticket/22972>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/063.c29c61bf3e3e7d8dcecc6c34613b5753%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.