[Django] #22972: HashedFilesMixin

44 views
Skip to first unread message

Django

unread,
Jul 7, 2014, 2:36:25 PM7/7/14
to django-...@googlegroups.com
#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.

Django

unread,
Jul 7, 2014, 2:41:29 PM7/7/14
to django-...@googlegroups.com
#22972: HashedFilesMixin.patterns should limit URL matches to their respective
filetypes
-------------------------------------+-------------------------------------
Reporter: alex.ehlke@… | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.staticfiles | Version: 1.7-rc-1
Severity: Normal | Resolution:
Keywords: HashedFilesMixin | Triage Stage:
CachedFilesMixin staticfiles | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by anonymous):

* needs_docs: => 0
* needs_better_patch: => 0
* needs_tests: => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/22972#comment:1>

Django

unread,
Jul 7, 2014, 3:56:36 PM7/7/14
to django-...@googlegroups.com
#22972: HashedFilesMixin.patterns should limit URL matches to their respective
filetypes
-------------------------------------+-------------------------------------
Reporter: alex.ehlke@… | Owner: aehlke
Type: Uncategorized | Status: assigned

Component: contrib.staticfiles | Version: 1.7-rc-1
Severity: Normal | Resolution:
Keywords: HashedFilesMixin | Triage Stage:
CachedFilesMixin staticfiles | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by aehlke):

* owner: nobody => aehlke
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/22972#comment:2>

Django

unread,
Jul 7, 2014, 3:56:53 PM7/7/14
to django-...@googlegroups.com
#22972: HashedFilesMixin.patterns should limit URL matches to their respective
filetypes
-------------------------------------+-------------------------------------
Reporter: alex.ehlke@… | Owner: aehlke
Type: Uncategorized | Status: assigned
Component: contrib.staticfiles | Version: 1.7-rc-1
Severity: Normal | Resolution:
Keywords: HashedFilesMixin | Triage Stage:
CachedFilesMixin staticfiles | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by aehlke):

I'm preparing a test case and patch.

--
Ticket URL: <https://code.djangoproject.com/ticket/22972#comment:3>

Django

unread,
Jul 8, 2014, 11:33:19 AM7/8/14
to django-...@googlegroups.com
#22972: HashedFilesMixin.patterns should limit URL matches to their respective
filetypes
-------------------------------------+-------------------------------------
Reporter: alex.ehlke@… | Owner: aehlke
Type: Uncategorized | Status: assigned
Component: contrib.staticfiles | Version: 1.7-rc-1
Severity: Normal | Resolution:
Keywords: HashedFilesMixin | Triage Stage:
CachedFilesMixin staticfiles | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by aehlke):

I've submitted a pull request with test coverage (a test which fails
before applying the patch) and patch for the fix. Please let me know if
anything needs changing.

--
Ticket URL: <https://code.djangoproject.com/ticket/22972#comment:4>

Django

unread,
Jul 8, 2014, 11:34:51 AM7/8/14
to django-...@googlegroups.com
#22972: HashedFilesMixin.patterns should limit URL matches to their respective
filetypes
-------------------------------------+-------------------------------------
Reporter: alex.ehlke@… | Owner: aehlke
Type: Uncategorized | Status: assigned
Component: contrib.staticfiles | Version: 1.7-rc-1
Severity: Normal | Resolution:
Keywords: HashedFilesMixin | Triage Stage:
CachedFilesMixin staticfiles | Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by aehlke):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/22972#comment:5>

Django

unread,
Jul 8, 2014, 11:34:55 AM7/8/14
to django-...@googlegroups.com
#22972: HashedFilesMixin.patterns should limit URL matches to their respective
filetypes
-------------------------------------+-------------------------------------
Reporter: alex.ehlke@… | Owner: aehlke
Type: Bug | Status: assigned

Component: contrib.staticfiles | Version: 1.7-rc-1
Severity: Normal | Resolution:
Keywords: HashedFilesMixin | Triage Stage:
CachedFilesMixin staticfiles | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by aehlke):

* type: Uncategorized => Bug


--
Ticket URL: <https://code.djangoproject.com/ticket/22972#comment:6>

Django

unread,
Jul 8, 2014, 11:35:09 AM7/8/14
to django-...@googlegroups.com
#22972: HashedFilesMixin.patterns should limit URL matches to their respective
filetypes
-------------------------------------+-------------------------------------
Reporter: alex.ehlke@… | Owner: aehlke
Type: Bug | Status: assigned
Component: contrib.staticfiles | Version: master

Severity: Normal | Resolution:
Keywords: HashedFilesMixin | Triage Stage:
CachedFilesMixin staticfiles | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by aehlke):

* version: 1.7-rc-1 => master


--
Ticket URL: <https://code.djangoproject.com/ticket/22972#comment:7>

Django

unread,
Jul 11, 2014, 10:30:12 AM7/11/14
to django-...@googlegroups.com
#22972: HashedFilesMixin.patterns should limit URL matches to their respective
filetypes
-------------------------------------+-------------------------------------
Reporter: alex.ehlke@… | Owner: aehlke
Type: Bug | Status: closed
Component: contrib.staticfiles | Version: master
Severity: Normal | Resolution: fixed

Keywords: HashedFilesMixin | Triage Stage:
CachedFilesMixin staticfiles | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by aehlke):

* status: assigned => closed
* resolution: => fixed


--
Ticket URL: <https://code.djangoproject.com/ticket/22972#comment:8>

Django

unread,
Jul 11, 2014, 10:32:08 AM7/11/14
to django-...@googlegroups.com
#22972: HashedFilesMixin.patterns should limit URL matches to their respective
filetypes
-------------------------------------+-------------------------------------
Reporter: alex.ehlke@… | Owner: aehlke
Type: Bug | Status: closed
Component: contrib.staticfiles | Version: master
Severity: Normal | Resolution: fixed
Keywords: HashedFilesMixin | Triage Stage:
CachedFilesMixin staticfiles | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by aehlke):

This patterns property is also documented in the Django docs, which I
think adds priority to getting this fixed as it makes it sound like
something you can extend (where in current versions you cannot actually
extend without subtly broken behavior.)

--
Ticket URL: <https://code.djangoproject.com/ticket/22972#comment:9>

Django

unread,
Jul 11, 2014, 11:11:10 AM7/11/14
to django-...@googlegroups.com
#22972: HashedFilesMixin.patterns should limit URL matches to their respective
filetypes
-------------------------------------+-------------------------------------
Reporter: alex.ehlke@… | Owner: aehlke
Type: Bug | Status: new

Component: contrib.staticfiles | Version: master
Severity: Normal | Resolution:
Keywords: HashedFilesMixin | Triage Stage:
CachedFilesMixin staticfiles | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timo):

* status: closed => new
* resolution: fixed =>


Comment:

A ticket shouldn't be closed until the fix is committed to Django.

--
Ticket URL: <https://code.djangoproject.com/ticket/22972#comment:10>

Django

unread,
Jul 11, 2014, 11:58:40 AM7/11/14
to django-...@googlegroups.com
#22972: HashedFilesMixin.patterns should limit URL matches to their respective
filetypes
-------------------------------------+-------------------------------------
Reporter: alex.ehlke@… | Owner: aehlke
Type: Bug | Status: new
Component: contrib.staticfiles | Version: master
Severity: Normal | Resolution:
Keywords: HashedFilesMixin | Triage Stage:
CachedFilesMixin staticfiles | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by aehlke):

timo: Ah ok, sorry about that. Thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/22972#comment:11>

Django

unread,
Aug 13, 2014, 8:49:51 AM8/13/14
to django-...@googlegroups.com
#22972: HashedFilesMixin.patterns should limit URL matches to their respective
filetypes
-------------------------------------+-------------------------------------
Reporter: alex.ehlke@… | Owner: aehlke
Type: Bug | Status: new
Component: contrib.staticfiles | Version: master
Severity: Normal | Resolution:
Keywords: HashedFilesMixin | Triage Stage: Accepted
CachedFilesMixin staticfiles | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1
* stage: Unreviewed => Accepted


Comment:

I left comments for improvement on the PR. Please uncheck "Patch needs
improvement" when you update it, thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/22972#comment:12>

Django

unread,
Oct 29, 2015, 10:13:55 AM10/29/15
to django-...@googlegroups.com
#22972: HashedFilesMixin.patterns should limit URL matches to their respective
filetypes
-------------------------------------+-------------------------------------
Reporter: alex.ehlke@… | Owner: aehlke
Type: Bug | Status: new
Component: contrib.staticfiles | Version: master
Severity: Normal | Resolution:
Keywords: HashedFilesMixin | Triage Stage: Accepted
CachedFilesMixin staticfiles |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by jaylett):

Is this the same as #19670?

--
Ticket URL: <https://code.djangoproject.com/ticket/22972#comment:13>

Django

unread,
Apr 21, 2016, 10:35:20 AM4/21/16
to django-...@googlegroups.com
#22972: HashedFilesMixin.patterns should limit URL matches to their respective
filetypes
-------------------------------------+-------------------------------------
Reporter: alex.ehlke@… | Owner: aehlke
Type: Bug | Status: closed
Component: contrib.staticfiles | Version: master
Severity: Normal | Resolution: duplicate

Keywords: HashedFilesMixin | Triage Stage: Accepted
CachedFilesMixin staticfiles |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by claudep):

* status: new => closed
* resolution: => duplicate


Comment:

Replying to [comment:13 jaylett]:


> Is this the same as #19670?

I think so.

--
Ticket URL: <https://code.djangoproject.com/ticket/22972#comment:14>

Reply all
Reply to author
Forward
0 new messages