Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
According to the CSS spec at http://www.w3.org/TR/CSS21/syndata.html#uri, the url() property can include whitespace before and after the URI. The regular expression in drupal_build_css_cache() needs to be modified to take this into account. Otherwise, images included in some CSS files do not get their paths corrected according to the aggregated CSS file's location.
See the attached patch.
Comment | File | Size | Author |
---|---|---|---|
#30 | css_url_regex_30.patch | 2.69 KB | ridgerunner |
#21 | cssurlregexp.patch | 1.65 KB | casey |
#17 | cssurlregexp_1.patch | 2.04 KB | casey |
#16 | cssurlregexp.patch | 1.65 KB | casey |
#13 | cssurlregexp.patch | 1.76 KB | casey |
Comments
Comment #1
lilou CreditAttribution: lilou commentedFollow here : #289293: CSS Aggregation: regexp mangles URL's in CSS
Comment #2
Gribnif CreditAttribution: Gribnif commentedPlease re-read the description. This is a separate issue from #289293: CSS Aggregation: regexp mangles URL's in CSS. That one has to do with path elements containing exactly two-characters. The bug described above has to do with spaces before and after the URI.
I did report the same problem as that other issue, but it was in #255293: Incorrect regexp causes some aggregated CSS refs to fail.
Comment #3
Anonymous (not verified) CreditAttribution: Anonymous commentedYes, definitely a different issue. The patch looks good but I need to test it.
Comment #4
Anonymous (not verified) CreditAttribution: Anonymous commentedSpeaking of testing, can you provide a simpletest for this? We need to not break it in the future.
Comment #5
hass CreditAttribution: hass commentedsubscribe
Comment #6
hass CreditAttribution: hass commentedColor module is missing in the patch.
Comment #7
kscheirerI'm not sure how we would test this. I guess there needs to be a dummy simpletest.css file that has urls with leading and trailing whitespace. Then execute
drupal_build_css_cache()
and check the resulting file for the correct paths?Or we could store the regular expression as a variable or constant, and write a check against it directly using
$this->assertPattern()
?Comment #8
casey CreditAttribution: casey commentedtagging
Comment #9
casey CreditAttribution: casey commentedComment #10
casey CreditAttribution: casey commentedAfter this one i'll have a look at
#265719: CSS aggregator produces invalid code and directory names for @import files Breaks IE, Internet explorer does not style page.
#511998: CSS aggregator change url path in imported files
Comment #11
c960657 CreditAttribution: c960657 commentedWhite-space is also allowed before the trailing semicolon.
A minor nit: I suggest moving the first new \s* into the parenthesis to prevent unnecessary backtracking caused by the two battling \s* when there is no
url(
prefix, i.e. like this:White-space is also allowed here before the trailing semicolon.
Apart from that, it looks good.
Looks like some tests are much needed. There is already one CSS aggregation test in modules/simpletest/tests/common.test.
Comment #12
casey CreditAttribution: casey commentedhmmm patch is still pretty broken.
Comment #13
casey CreditAttribution: casey commentedReroll with suggestions from c960657.
Comment #14
jhedstromSubscribing
Comment #15
hargobindsubscribing
Comment #16
casey CreditAttribution: casey commentedReroll
Comment #17
casey CreditAttribution: casey commentedReroll
Comment #18
mikeytown2 CreditAttribution: mikeytown2 commentedDuplicates
#567086: Optimise CSS feature does not allow whitespace
#352042: drupal_build_css_cache() cannot deal with a url() statement not surrounded by spaces.
Comment #19
rfayNote that both items in #18 were D6 issues.
Comment #20
andypostsubscribe
There's a working patch in #444228: Optimize CSS option causes php cgi to segfault in pcre function "match"
Comment #21
casey CreditAttribution: casey commentedReroll. Can we get a RTBC here? This patch is so obvious.
@andypost, that patch is about something else.
Comment #22
andypostLast hunk seems removes ability to have space between url and (
Comment #23
casey CreditAttribution: casey commentedThat is how it is supposed to be; http://www.w3.org/TR/CSS21/syndata.html#uri
Comment #24
andypostSo it's looks fine except no tests. Could you extend a test from modules/simpletest/tests/common.test
within CascadingStylesheetsUnitTest class
Comment #25
casey CreditAttribution: casey commentedWhat should the test contain? whether an invalid url() in a stylesheet is skipped when being preprocessed? I am not sure this needs a test.
Comment #26
andypostI reviewed this again and see no reason to write a test for this preg so RTBC
Comment #27
casey CreditAttribution: casey commentedStill applies
Comment #28
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Thanks.
Comment #29
andypost@casey, Please, re-roll this for D6
Comment #30
ridgerunner CreditAttribution: ridgerunner commentedAll three regexes of the recently committed patch do not work correctly. They all now erroneously match absolute and external URLs if they are unquoted and have leading whitespace. Looking at the first of the three regexes, here is an example of what happens when
drupal_build_css_cache()
processes susceptible external and absolute URLs:The erroneous match happens because the \s* expression is able to give up one of its spaces to allow the negative lookahead to incorrectly match absolute and external URLs (at a position one space back from where the URL string actually starts). This problem is easily fixed for this particular regex by adding a possessive + to the first \s* expression.
The attached patch possessifies the \s* and all other applicable quantifiers to both fix the above mentioned bug and to improve efficiency (especially for non-matches). This patch also fixes another nasty bug (in the last regex in
drupal_load_stylesheet_content()
) where @imports having absolute URLs (which should be ignored and left alone) were instead being matched and then effectively deleted. This patch also adds the whitespace fix to the identical URL matching regex in the color module which was overlooked by the previous patch.Comment #31
andypostIt seems reasonable I've not tested previous patch with baseurl.
@ridgerunner How can I help to test this?
Comment #32
kscheirerseems like we should roll back this commit and then get some tests in place with a new patch.
Comment #33
andypostSuppose a follow-up is enough
Comment #34
Wim LeersSetting back to state of commit at #28. Please open a new issue if there is still a bug.
The problems indicated in #30 are only possible because #21 got committed without additional test coverage. Sad. But still, please open a new issue. It's been sitting here for almost 3 years because it's so hard to find.