Closed (outdated)
Project:
Drupal core
Version:
7.x-dev
Component:
base system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
25 Mar 2009 at 13:01 UTC
Updated:
19 Jul 2024 at 08:26 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
jax commentedWhen parsing the css file the preg_replace_callback calls _drupal_build_css_path with the following matches:
Let's see if I can find out what's wrong with the regexp....
Comment #2
jax commentedWhen trying the expression in python:
it works. So it might be a PHP version issue.
Comment #3
jax commentedIt chokes on the attached file with a stock PHP 5.2.5 and a 5.2.0-8+etch13 (on Debian). So it must be something with the expression. I've attached the file for further inspection.
Comment #4
jax commentedActually the css is already botched when
is called on the css file
Comment #5
jax commentedOk, I'm pretty sure that I've found where it is going wrong.
The style.css is the file described above. When it comes in
drupal_load_stylesheet()it encounters:Which recursively calls _drupal_load_stylesheet() for the matched elements. If tracked what it the call returns when it was called with 'structure.css' and that css is still valid. But when I check what the preg_replace has returned it is botched.
#electro_cover{margin:15px 0;}#electro_cover a{background:url(../images/loop_cover.gif);display:block;height:206px;width:207px;}becomes
#electro_cover a{background:url(./display:block;height:206px;width:207px;}So, there is definately something wrong with the @import replacement css.
Comment #6
jax commentedTest case:
structure.css:
style.css:
Resulting css code:
Comment #7
jax commentedSigh, I didn't see the underscore. The culprit is:
That last one is incorrect.
Comment #8
jax commentedI'm pretty sure that last regexp should have a "@import" in there as well because else it replaces all the url() instances that match and not only the @import statements.
Comment #9
jax commentedI've tested this issue with 7.x dev and it's still there. I've attached a theme that allows testing. Follow these steps to reproduce:
#elektro_cover a{background:url(./}There is probably something wrong with the regexp in
_drupal_load_stylesheet($matches).Comment #10
jax commentedDamn, I screwed up the testtheme, it has a path outside the theme's dir. Here's a better test theme.
Comment #11
jax commentedI'm pretty sure that the original code has never worked. The first back reference is whether or not the url starts with a quote. The whole point of the replace is to add the sub-path within the theme directory.
The patch seems to resolve the problem for first and second level @imports.
Comment #12
grim assim commentedwhoa!
I have been looking into why the css optimization fails on my site D6 but only under IE (I have seen a few posts about this) it seems that FF/Chrome will still pass the broken css file.
I jimmied your patch into my site and it works flawlessly.
Mainly wanted to thank you for the time you have put into this bug!
*Thanks*
Comment #13
jax commentedI've been using it on a couple of sites as well now and I really want this to hit D7 and D6.11 since I'd rather not have to patch core each time I turn on css optimization with a design that uses @import.
Since it works for you and me I'm putting this in reviewed and tested.
Comment #14
hass commentedI wonder about this thought to have this tested while developing the optimizer #113607: Import @import commands when building CSS cache in D6 times... isn't there a way to fix the regex if there is something wrong? Don't set your own patches to RTBC, please.
Have you tested all @import variants? for e.g.
Comment #15
hass commentedMay be a duplicate of #258846: CSS aggregation fails to parse some url()'s
Comment #16
jax commentedIt's not really a duplicate, this one is just one more thing that is wrong with the CSS parsing.
Comment #17
kkaefer commentedSee also #265719: CSS aggregator produces invalid code and directory names for @import files Breaks IE, Internet explorer does not style page.
Comment #18
kkaefer commentedAlso see #289293: CSS Aggregation: regexp mangles URL's in CSS and #360055: CSS Aggregation does not work correctly
Comment #19
caktux commentedjust some extra info about @import i read the other day : http://ajaxian.com/archives/souders-dont-use-import
Comment #20
cburschkaDuplicate or not, the indentation needs to be fixed on one of the added lines. :)
That page about @import is very interesting; I've always wondered which way is better. However, Drupal's CSS aggregator needs to support all directives including @import, even if we don't use it in core...
Comment #21
casey commentedtagging
Comment #22
casey commentedComment #23
dropiopio commentedI have the same issue still in drupal 7.2
Draggable icon of dashboard.css from misc dir is not loaded after css aggregation.
Views UI also suffers.
I tried various browser, web servers, base url at settings.php.
Nothing worked.
Any other idea? Or it is a bug in rare cases?
Comment #24
sunComment #25
cburschkaThe bug is no longer in Drupal 8. While the replacement string wasn't changed, the pattern was fixed to only match the string up to the (optional) opening quote. Instead of capturing the actual path, it is now only checked with a lookahead assertion that makes sure it is not an absolute URL (starting with / or a protocol identifier). The #electro_cover example above works correctly.
I have not checked if the bug is still in 7.x. If not, this should be closed.
Comment #26
lundj commentedI still see the bug in the latest Drupal 7 version. Is there a patch/backport planned for this?
Comment #28
anrikun commentedHere's a direct port of the patch committed for D9 at #2936067: CSS aggregation fails on many variations of @import
Comment #29
avpadernoThe previous patch did not run tests. I attached the same patch with a different filename.
Comment #31
avpadernoI created a merge request, since patches are no longer tested.
Comment #32
poker10 commentedThanks for working on this! It seems like there is still some work needed.
Issue summary seems to be outdated, as we are not fixing relative paths, but @imports.
Parent issue updated the tests, here the test changes are missing.
I am also a bit confused about #25, which states that the issue no longer affected D8 (13 years ago) and then there was a commit/fix in D9 3 years ago (in this issue #2936067: CSS aggregation fails on many variations of @import, started 7 years ago). So we need to be sure what we are fixing here.
Comment #33
avpadernoComment #9 changed from CSS optmization fails on relative paths to CSS optmization fails on css files that use @import, although the same comment still describes the issue being with relative paths.
Comment #34
avpaderno#2936067: CSS aggregation fails on many variations of @import does not seem to fix an issue with relative paths. It seems this issue and that issue are not related.
We should check for an issue for Drupal 8+ which changes the regular expression this issue propose to change.
Comment #35
avpadernoComment #25 seems to hit the nail.