Closed (duplicate)
Project:
Drupal core
Version:
8.0.x-dev
Component:
asset library system
Priority:
Major
Category:
Bug report
Assigned:
Issue tags:
Reporter:
Created:
14 Nov 2014 at 05:19 UTC
Updated:
7 Jan 2016 at 17:06 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
grendzy commentedComment #2
grendzy commentedComment #3
grendzy commentedComment #5
David_Rothstein commentedLinking to a couple related issues, and clarifying the title. I haven't tried out the patch here but the approach looks nice and simple.
I actually thought that was the issue that caused the regression in Drupal 8? But either way, my understanding is that this broken in D8 only and that D7 handles it correctly.
Comment #7
mfbThis looks good to me. Patch still applies. Given that multiple protocols and hosts may point at a drupal site, I can't think of a good reason why drupal should use absolute URLs inside CSS files out-of-the-box. A module can always use hook_file_url_alter() to do that or anything else to the URLs.
Comment #8
mfbAlso going to make this "major" as it resolves some mixed-content warnings on d8 sites available via both HTTP and HTTPS.
Comment #9
wim leers+1000
Working on a review.
Comment #10
wim leersConfirmed that this is a problem.
Working on test coverage.
Comment #11
wim leersThe patch is a solution to the problem. Because of this:
i.e. this patch makes it so that
CssOptimizercreates root-relative URLs instead of a shipped file path. Which means it is handled by the first branch, not the second.However, note this does go against the original spirit of how file URLs are supposed to be passed around inside Drupal: they're supposed to be relative to Drupal's root on the file system root, not relative to Drupal's base URL. And without a leading slash. i.e.
core/assets/vendor/jquery/jquery.js, not/subdirectory/assets/vendor/jquery/jquery.js.It'd be better to fix the second branch in
file_create_url(). That'd fix this everywhere: all shipped files (jQuery, theme CSS, etc) would automatically use relative URLs.Attached patch keeps the existing approach. The test-only patch is also the interdiff.
In the next patch, I'll change to what is IMO the better solution.
Comment #13
wim leersD'oh. Accidentally excluded one crucial change.
These are the patches that should've been attached to #11.
Ignore the patches in #11.
Comment #14
wim leersAs promised:
Here you go.
Comment #19
mfbI'd worry this could cause breakage for code expecting an absolute URL (often needed outside the site context, such as rendering an e-mail message). Perhaps file_create_url() should accept an $options array so you could pass in ['absolute' => TRUE] when needed?
Comment #20
wim leersBut images in e-mail messages (or RSS feeds) are uploaded, they're not shipped. Hence they are of the form
public://cat.jpg, not of the formcore/assets/vendor/jquery/jquery.js. Those files will still get absolute URLs: their URLs are generated in the stream wrapper's code, for example\Drupal\Core\StreamWrapper\PublicStream::getExternalUrl().Something like that is indeed what is necessary in the long run. i.e. the problem is that
file_create_url()is not aware about the context in which its return value will be used, and it's necessary to know that to return the ideal value. We had similar problems about not knowing the context in which data was going to be used in Twig/text sanitization/rendering. This is just one problem that far fewer people ever deal with, so far fewer eyes are on it.Now it should pass tests.
Comment #21
wim leersComment #23
wim leersFixed those last few failures.
Comment #24
wim leersI'm also working on #1494670: References to CSS, JS, and similar files should be root-relative URLs: avoids mixed content warnings & fewer bytes to send, and part of the problem described in that issue is fixed by this issue/patch.
However, upon reading through that entire issue (and the approach in the patch there), I encountered
file_url_transform_relative(), which was introduced in #1494670: References to CSS, JS, and similar files should be root-relative URLs: avoids mixed content warnings & fewer bytes to send by … ironically … me :P That approach seems clearly superior.Instead of a very small chance of breakage (changing
file_create_url()this patch), it has zero chance of breakage (usingfile_url_transform_relative()). So, let's throw out the very very very painful/frustrating work I did with updating all of these pesky tests.… but then this issue effectively becomes a strict subset of #1494670: References to CSS, JS, and similar files should be root-relative URLs: avoids mixed content warnings & fewer bytes to send. So, I moved the changes here that were still missing in #1494670's patch there, see #1494670-71: References to CSS, JS, and similar files should be root-relative URLs: avoids mixed content warnings & fewer bytes to send.