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
Comment #1
universalhandle commentedHere'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 :-)
Comment #2
quicksketchThanks, 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.
Comment #3
universalhandle commentedGood catch. Shall I roll a new patch, then?
Comment #4
universalhandle commentedHere's a new patch to account for your suggestion in comment #2.
Comment #5
universalhandle commentedCould 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
Comment #6
quicksketchI'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.
Comment #7
quicksketchI've committed this simplified patch.
Comment #8
sauce71 commentedThis patch broke my site, shows no images after upgrading the module to 6.x 1.13 ... will investigate it further
Comment #9
quicksketchThanks sauce71, let me know what you find out.
Comment #11
sauce71 commentedFinally got around to investigate this: setting $base_url in settings.php solved my problem