Zen subthemes by default have inline images for drupal_set_message() boxes and such (css/components/misc.css):

/**
 * Messages.
 */
.messages,
.messages--status,
.messages--warning,
.messages--error {
  background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYA…');
}

But when CSS aggregation is enabled, these images don't appear, because a path is being prepended to the value inside url():

.messages,.messages--status,.messages--warning,.messages--error{background-image:url(components/'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYA…');

The culprit is a regex in _drupal_load_stylesheet() which is not greedy enough:

  return preg_replace('/url\(\s*([\'"]?)(?![a-z]+:|\/+)/i', 'url(\1'. $directory, $file);

It's trying to make sure it's not firing against absolute paths, or URIs with a protocol (like data:), but it's not working correctly; in the case of url('relative/path'), the regex will pass with \1 being "url('", but in the case of url('data:foo'), the regex still passes, just with \1 being "url(" (no inner quote). I'm guessing there's some branch earlier in the code that stops this from firing with absolute paths or protocoled URLs already, or else I don't see why this wouldn't have caused more obvious problems…

After trying to prod the regex for a bit to stop it from doing that, I just went ahead and replaced it with one based on the more complex pattern in drupal_build_css_cache(), though I try to still keep the quote style (or lack thereof) in the original intact just as the original code does.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Garrett Albright’s picture

Issue tags: +CSS aggregation
Garrett Albright’s picture

Status: Active » Needs review
Garrett Albright’s picture

Version: 7.x-dev » 8.x-dev
FileSize
731 bytes
8.67 KB

Aiming for more attention for this by bumping to D8, attaching a D8 patch, and also attaching a D8 subtheme of "stark" which replicates the problem. You should see the Druplicon tile in the background if things work correctly, but you won't before applying the patch.

To clarify the problem, as the theme demonstrates, this happens if you have a data: URL in a CSS file which is @included from another CSS file. If you have a data: URL in a CSS file which is added any other way, there's no problem.

Garrett Albright’s picture

Component: other » CSS

Reassigning to CSS because perhaps it's watched more than "other."

tim.plunkett’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

This should be testable, right?

Garrett Albright’s picture

A test, and a re-roll which includes it.

tim.plunkett’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 6: 2142441-6_css_data_paths_aggregation_test_only-d8.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

Protip: If you order them in the opposite order, it won't mark the issue needs work.

I don't know enough about our aggregation code or expectations to RTBC, but the test fails make sense.

Wim Leers’s picture

Status: Needs review » Needs work

Looks great! :) Just some small remarks:

  1. +++ b/core/tests/Drupal/Tests/Core/Asset/CssOptimizerUnitTest.php
    @@ -174,6 +174,7 @@ function providerTestOptimize() {
    +      // - Don't adjust the "path" of an inline image (https://drupal.org/node/2142441)
    

    Why not just refer to "data URIs" instead of "path of an inline image"?

  2. +++ b/core/tests/Drupal/Tests/Core/Asset/css_test_files/css_input_with_import.css.optimized.css
    @@ -1,4 +1,4 @@
    +ul,select{font:1em/160% Verdana,sans-serif;color:#494949;}.ui-icon{background-image:url(images/icon.png);}.druplicon{background-image:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFgAAABkCAYAAAACLffiAAAPCElEQVR42u1dCVBUVxZ9gIlGzabJxKSSVGUyqdTETCqT1CSVyTqlqUwSEZBNFjFq1LjEBXdBNsMqOyKbSEBcQUVBBVFExQVFBcEFFJBdZN+hWe7c95wve/O7+zc08E/VLZbm//7/9H3n3XvffR+i8jB0yySmPu8SEcqBuo5NB9G1byGm2ycSEQLD1Hfyfx0i4JWV+4DoO1cREQLDxHuVXdR1+GV/BhAzPyCz3bKICAEx2/3S8fRiCE0pBrLmFBAjDzTPU0SEQJj1R2tRTTMk5VY/Idg8DoiBCxBjL28iQkGY+Mz6ynofUGQ8qmcEM1t9AoiuAxBTbwMiQgEYuhZG3igAisyyRtBYF99J8spoINo2gBq9noiQb3J7d9kOaO/oAIrb6MFjN5ym5HYnWdeekryOiJBJGsaNN3JuSy2sAQ7HbpdRUnvbquOAOk01OYSI4AHT7X9T17VvPYzSwKG6qRWWR2X2STCnySgnT0K4Ob4aRES/nqv9golze+ydR8Chpa0D9qWWwgculyiZUo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jx1C2V8W+8PUdaHMw7/bepDprJbrUbbK8cHaUNykEthPJc6NeSxeVzsSG8eqYcMZ6CUaRNvagaXaODPjz0OXLGjb0B2YTXgde5HYV8mIwyy7L1A+YogmzYpsaeFEXq3mX5hhpG5uwZArBcuLC5FYdTIagJ78Gd40km1RyLY8IeEYjbAwSea42tCVHYfHU0LZ8EejIyYeR48dEYEwcJ6OHuaApMcjObnsYZszLevx5xY06DRLJJCaRStaI61u4c/Z+FoCjg43/KB02ESrAvgfBn5JXUUR7bgAAAAASUVORK5CYII=");}
    

    Could you please test with a smaller data URI? :) That makes the tests easier to verify.

    The smallest one known to mankind: http://stackoverflow.com/a/13139830/80305

  3. This tests the url("data:…") case, but I'd also like to see tests for the url('data:…') and url(data:…) cases.
Garrett Albright’s picture

Okay, here's examples with all three quote styles, with teensy images (well, almost… thanks, JPEG).

Interestingly, this reveals that this bug isn't actually happening with data URIs which aren't quoted… Here's the buggy output of the relevant line. Note that the .data .no-quote one doesn't have the "../".

ul,select{font:1em/160% Verdana,sans-serif;color:#494949;}.ui-icon{background-image:url(file_create_url:/Users/Albright/Sites/d8.test/www/core/tests/Drupal/Tests/Core/Asset/css_test_files/images/icon.png);}.data .double-quote{background-image:url(../"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7");}.data .single-quote{background-image:url(../'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDACAWGBwYFCAcGhwkIiAmMFA0MCwsMGJGSjpQdGZ6eHJmcG6AkLicgIiuim5woNqirr7EztDOfJri8uDI8LjKzsb/2wBDASIkJDAqMF40NF7GhHCExsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsb/wAARCAABAAEDASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAb/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhEDEQA/AKAAH//Z');}.data .no-quote{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACEAAAAEAQAAAAAo/mtHAAAAIElEQVQIHWMRnWHwcRNLN8NZ7QYWwT8PlBlYsgqVBRsAankIMw5MtnoAAAAASUVORK5CYII=);}

The last submitted patch, 11: 2142441-11_css_data_paths_aggregation_test_only-d8.patch, failed testing.

RainbowArray’s picture

+++ b/core/tests/Drupal/Tests/Core/Asset/css_test_files/import1.css
@@ -3,4 +3,18 @@ ul, select {
\ No newline at end of file

Looks like a newline may be needed?

The last submitted patch, 11: 2142441-11_css_data_paths_aggregation_test_only-d8.patch, failed testing.

star-szr’s picture

I think that newline warning is from the pre-patch file.

RainbowArray’s picture

Status: Needs review » Reviewed & tested by the community

Given that, and that this still passes, looks RTBC to me.

Wim Leers’s picture

Issue tags: +front-end performance, +Performance, +CSS

Wonderful, thank you for improving D8's aggregation :)

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Wow, very nice find! Thanks too for the tests so we don't break this again. :)

Committed and pushed to 8.x. Thanks!

  • webchick committed 7a9f3fb on 8.0.x
    Issue #2142441 by Garrett Albright: Fixed CSS aggregator prepends data:...
alexpott’s picture

Committed 42570bb and pushed to 8.0.x. Thanks!

Edit: Nope @webchick committed this one :)

Garrett Albright’s picture

Version: 8.0.x-dev » 7.x-dev
Status: Fixed » Needs work
Issue tags: +Needs backport to D7

This problem is also still present in D7. I'll try to get a D7 patch ready over the weekend, if not later today, if nobody beats me to it.

Garrett Albright’s picture

Title: CSS aggregator prepends data: URLs with paths » [Followup needed] CSS aggregator prepends data: URLs with paths
Version: 7.x-dev » 8.0.x-dev
Priority: Normal » Major
Status: Needs work » Needs review
FileSize
20.75 KB

Angie, I noticed that you seem to have accidentally committed an older patch to the repo - #6, instead of #11. As per xjm's instructions in #drupal-contribute, here's a diff between the current state of the repo and where it would be had #11 been committed instead.

chx’s picture

Status: Needs review » Reviewed & tested by the community

Here's what I did:

➜  d8 git:(2142441) ✗ git revert  7a9f3fb
[2142441 608d8e9] Revert "Issue #2142441 by Garrett Albright: Fixed CSS aggregator prepends data: URLs with paths."
 5 files changed, 19 insertions(+), 25 deletions(-)
 rewrite core/tests/Drupal/Tests/Core/Asset/css_test_files/css_input_with_import.css.optimized.css (91%)
 rewrite core/tests/Drupal/Tests/Core/Asset/css_test_files/css_subfolder/css_input_with_import.css.optimized.css (92%)
 rewrite core/tests/Drupal/Tests/Core/Asset/css_test_files/import1.css (98%)
➜  d8 git:(2142441) ✗ curl -s https://www.drupal.org/files/issues/2132441-11_css_data_paths_aggregation-d8.patch|git apply --index
➜  d8 git:(2142441) ✗ git diff 8.0.x > 2142441_25.patch
➜  d8 git:(2142441) ✗ md5sum 2142441*
1eea651d719e989a813758095c04a116  2142441-24_css_data_paths_correction.patch
1eea651d719e989a813758095c04a116  2142441_25.patch

Likely the patch was created this way, even 'cos they are the same byte-to-byte.

  • webchick committed f5884ce on 8.0.x
    Issue #2142441 by Garrett Albright: Fixed [Followup needed] CSS...
webchick’s picture

Status: Reviewed & tested by the community » Fixed

Oops. Dunno what I was doing there. :P Thanks for the new patch.

Committed and pushed the RIGHT one to 8.x. ;) Thanks!

Garrett Albright’s picture

Version: 8.0.x-dev » 7.x-dev
Priority: Major » Normal
Status: Fixed » Needs work

w00t! Stoked that we got this fixed before Beta 1.

Okay, back to 7.x we go.

Garrett Albright’s picture

Title: [Followup needed] CSS aggregator prepends data: URLs with paths » CSS aggregator prepends data: URLs with paths
Status: Needs work » Needs review
FileSize
8.39 KB
8.99 KB

D7 backport, here we go.

The last submitted patch, 29: css-aggregator-test-only-2142441-29-d7.patch, failed testing.

BenStallings’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for this, Garrett! Works like a charm.

David_Rothstein’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 7.x - thanks!

  • David_Rothstein committed c2b05dd on 7.x
    Issue #2142441 by Garrett Albright: Fixed CSS aggregator prepends data:...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

YesCT’s picture

Issue tags: -Needs backport to D7
YesCT’s picture

Issue tags: -front-end performance +frontend performance

changing to use the more common tag, so the less common one can be deleted, so it does not show up in the auto complete and confuse people.