This patch edits the module to use the base path when determining whether a file is local or remote. For cases in which Drupal is installed at a URL like example.org/drupal, the filter should treat files originating from URLs such as example.org/not-drupal/img.jpg as though they were remote files. The main reason for this is that when Drupal fetches the file for caching/resizing, you don't want it to use a relative URL like /drupal/not-drupal/img.jpg; instead you want to use an absolute URL: http://example.org/not-drupal/img.jpg.

In the unpatched code, the preg_replace on line 324 (331 of the patched file) checks for the existence of the domain plus base path in the image path, and replaces it with a blank. The unpatched code would treat an image at http://example.org/not-drupal/img.jpg as local (because it starts with http://example.org), but the aforementioned regex would fail to match, and you'd end up with a URL rather than a filepath when you get to is_file() further down the function.

Anyway, I've tested this patch and it resolves the issue on sites installed in a subdirectory, without hurting sites installed at the root of a domain. The patch was rolled according to these instructions: http://drupal.org/node/337087/git-instructions/6.x-1.x. If I was supposed to run them according to http://drupal.org/node/337087/git-instructions/master instead, let me know and I'll run it again.

Comments

universalhandle’s picture

Here's the patch. I guess I had to submit the bug in order to get the issue ID, in order to properly name the patch... Yeesh :-)

quicksketch’s picture

Thanks, though we should still preg_quote($_SERVER['HTTP_HOST']), because things like periods in regular expressions mean "any character", which could lead to false positives.

universalhandle’s picture

Good catch. Shall I roll a new patch, then?

universalhandle’s picture

Here's a new patch to account for your suggestion in comment #2.

universalhandle’s picture

Could you commit this? It'd be great to get this in the repository so I don't clobber the bugfix with future updates.

Thanks,
-Pitt

quicksketch’s picture

I'll commit it next time I'm working on Image Resize Filter. It still has nitpicky changes that I'd like to address, like if we're going to use '#' as the regex delimiter we should also pass '#' into preg_escape(). Comments should describe what the code is doing and avoid use of "you" and "we". These are minor gripes of course, the code works. I'll definitely commit it before the next release.

quicksketch’s picture

Status: Needs review » Fixed
StatusFileSize
new769 bytes

I've committed this simplified patch.

sauce71’s picture

This patch broke my site, shows no images after upgrading the module to 6.x 1.13 ... will investigate it further

quicksketch’s picture

Thanks sauce71, let me know what you find out.

Status: Fixed » Closed (fixed)

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

sauce71’s picture

Finally got around to investigate this: setting $base_url in settings.php solved my problem