#21080: collectstatic post-processing fails for references inside comments
-------------------------------------+------------------------------------
     Reporter:  shreyas@…            |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  contrib.staticfiles  |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+------------------------------------

Comment (by powderflask):

 Re: comment:6  is a slightly different issue and MUCH easier to patch.

 This issue is caused by generators (like http://jqueryui.com/themeroller)
 that urlencode stuff in a comment block.
 E.g.
 {{{
 /*! jQuery UI - v1.12.1 - 2016-09-14
   * http://jqueryui.com
   * Includes: core.css, accordion.css, ...
   * To view and modify this theme, visit
 http://jqueryui.com/themeroller/?...&iconsHover=url(%22images%2Fui-
 icons_555555_256x240.png%22)...
   * Copyright jQuery Foundation and other contributors; Licensed MIT */
 }}}

 The regular expression in storage.HashedFilesMixin matches `url(...)` in
 the comment, but it does NOT unquote the urlencoded quotation mark: `%22`
 The last step of `converter()` unquotes the transformed url:  `return
 template % unquote(transformed_url)`,  converting the urlencoded quotation
 marks back, and thus messing up the filename, as can be seen in the posted
 stack trace:
 {{{
     The file 'jquery-ui-dist/"images/ui-icons_555555_256x240.png"' could
 not be found...
 }}}
 (Notice the excess quotation marks in the path.)

 == Patch:
 storage.py line 61
 `-          r"""(url\(['"]{0,1}\s*(.*?)["']{0,1}\))""", `
 `+
 r"""(url\((?:['"]|%22|%27){0,1}\s*(.*?)(?:['"]|%22|%27){0,1}\))""", `

 This matches url encoded single- or double-quotes and fixed several such
 issues with 3rd party packages that included generated CSS files like
 this.

 IF a general fix for ignoring comments in CSS files is implemented, that
 would resolve this issue too.
 But IF NOT, this is a simple fix that prevents `collectstatic` from
 crashing on common 3rd party packages.

 Happy to submit a patch for this if this seems worthwhile.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/21080#comment:10>
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/075.4e8d78729f28487a67744ee8c5fcfbb0%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to