If my CDN server URL is //cdn.example.com/ when using image fields the image URL becomes //cdn.example.com//cdn.example.com/sites/default/files/my-image.png because image field generates the URL to the image which is fed through cdn_file_url_alter(), later the output html is fed through cdn_html_alter_image_urls() which also failed to take into account protocol relative URLs.
The first problem really lies in Drupal core's file_uri_scheme() as it doesn't understand protocol relative URLs, but I don't have the energy to have that fight atm. Instead I decided to add an extra condition to the protocol check in CDN to catch it.
The second problem is caused by the page wide image replacement which checks for base_path() as one of the patterns, so // matches when drupal is installed in the docroot (common use case for people wanting to use a CDN).
Patch coming right up.
Comment | File | Size | Author |
---|---|---|---|
#6 | 1466102-follow_up-6.patch | 1.25 KB | Wim Leers |
#1 | cdn-1466102-protocol-relative-1.patch | 1.63 KB | skwashd |
Comments
Comment #1
skwashd CreditAttribution: skwashd commentedAnd here it is...
Comment #2
Wim LeersExcellent find and excellent patch. I wish there were more contributors like you! :) I only added some docs and backported it to D6. Both commits attributed to you.
D7: http://drupalcode.org/project/cdn.git/commit/033dd53
D6: http://drupalcode.org/project/cdn.git/commit/5d42d04
Comment #3
Wim LeersNote that when you use ImageCache on D6, it breaks protocol-relative URLs:
The
url()
function in D6 does not honor protocol-relative URLs…Comment #5
Wim LeersThe committed patch contains a major bug.
preg_quote() is applied to all three items of the array. Unfortunately, you've added regexp syntax to one of the entries, which preg_quote() subsequently escapes… So this actually completely breaks the protocol-relative URL case!
Patch posted as part of the patch at #1535252-3: Support rewriting file URLs in blocks.
Comment #6
Wim LeersCommitted.
D7: http://drupalcode.org/project/cdn.git/commit/9ba07e2
D6: http://drupalcode.org/project/cdn.git/commit/e3d9d6e
Comment #8
Jody LynnIs the issue in comment #3 fixed? I am running into that one.
I have a patch to D6 url function in https://drupal.org/node/1783278
Comment #9
Jody LynnComment #10
Wim Leers#3 was a bug in the ImageCache module, not in the CDN module or Drupal 6 core.
(Sorry for the slow response :()