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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

skwashd’s picture

Status: Active » Needs review
FileSize
1.63 KB

And here it is...

Wim Leers’s picture

Title: CDN breaks URLs when using protocol relative URLs for CDN servers. » CDN module rewrites already rewritten protocol-relative URLs
Status: Needs review » Fixed

Excellent 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

Wim Leers’s picture

Note that when you use ImageCache on D6, it breaks protocol-relative URLs:

  drupal_alter('file_url', $altered_path);

  // If any module has altered the path, then return the alteration...
  if ($altered_path != $old_path) {
    // ...but use url() so our $bypass_browser_cache parameter is honored.
    return url($altered_path, $args);
  }

The url() function in D6 does not honor protocol-relative URLs…

Status: Fixed » Closed (fixed)

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

Wim Leers’s picture

Status: Closed (fixed) » Active

The 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.

Wim Leers’s picture

Status: Fixed » Closed (fixed)

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

Jody Lynn’s picture

Is 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

Jody Lynn’s picture

Issue summary: View changes
Status: Closed (fixed) » Needs work
Wim Leers’s picture

Status: Needs work » Closed (fixed)

#3 was a bug in the ImageCache module, not in the CDN module or Drupal 6 core.

(Sorry for the slow response :()