#32849: ManifestStaticFilesStorage newline breaks regex
-----------------------------------------------+------------------------
               Reporter:  TZanke               |          Owner:  nobody
                   Type:  Bug                  |         Status:  new
              Component:  contrib.staticfiles  |        Version:  3.2
               Severity:  Normal               |       Keywords:
           Triage Stage:  Unreviewed           |      Has patch:  0
    Needs documentation:  0                    |    Needs tests:  0
Patch needs improvement:  0                    |  Easy pickings:  0
                  UI/UX:  0                    |
-----------------------------------------------+------------------------
 Hello,

 I am trying to use the `ManifestStaticFilesStorage` static file handling.
 Right now i found a possible issue with line breaks.

 The file in which strings should be replaced is loaded as a string with
 line breaks:
 
https://github.com/django/django/blob/main/django/contrib/staticfiles/storage.py#L315

 The default regex may not have this issue, `default_template =
 """url("%(url)s")"""` cause a minifier will not break inside this `url()`
 method.
 
https://github.com/django/django/blob/main/django/contrib/staticfiles/storage.py#L45


 But in my case a more complex string with URL has to be replaced, so
 currently the string sometimes contains a line break.
 The line break now is not matched against the regex which leads to a
 caching problem.

 Expample:
 CKEditor4: https://cdn.ckeditor.com/4.16.1/standard/ckeditor.js
 Search for "styles/tableselection.css"
 First occurrence is split by line break.

 My regex: `(appendStyleSheet\(this\.path\+"([^'"]*?)"\))`
 Regex with newline support:
 `(appendStyleSheet\(this\s?\.\s?path\s?\+\s?"([^'"]*?)"\))`

 Question:
 Who is responsible for possible line breaks?
 Maybe Django should  load the content without line breaks?
 Or has the developer/user of ManifestStaticFilesStorage a responsibility
 to care for possible line breaks in his regexes?

 But: Maybe he (the developer) does not know this can happen. Later on,
 someone else changes the JS code => minifyer adds linebreaks => production
 => regex mismatch => caching problem

 Let me know whats your opinion.

 Best regards
 Tobias

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32849>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/049.b3bb38adf664bd8d0b596d1431221f87%40djangoproject.com.

Reply via email to