Closed (fixed)
Project:
CDN
Version:
6.x-2.0-rc5
Component:
Module
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
15 Nov 2010 at 15:56 UTC
Updated:
2 Dec 2010 at 22:00 UTC
Jump to comment: Most recent file
If you have any attributes in the img tag before the src attribute, they end up getting replaced with the <img="{cdn url}". An example of this is:
<img style="BORDER-BOTTOM: black 1px solid; BORDER-LEFT: black 1px solid; FLOAT: left; MARGIN-LEFT: 10px; BORDER-TOP: black 1px solid; MARGIN-RIGHT: 30px; BORDER-RIGHT: black 1px solid" src="http://www.thomhartmann.com/sites/default/files/resize/community-hands-257x172.jpg" alt="" width="257" height="172" />
When _cdn_preprocess_page_helper does the replacements it becomes:
<img src="http://www.thomhartmann.com/sites/default/files/resize/community-hands-257x172.jpg" alt="" width="257" height="172" />
The fix I put in was to change the arguments for the img parser in cdn.fallback.inc (line 59):
_cdn_preprocess_page_helper($variables['content'], $pattern, 2, 4, 5, '','');
Not sure if that's the best fix, but so far it is working for me.
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | 972344-11.patch | 5.56 KB | wim leers |
| #10 | 972344-10.patch | 3.41 KB | wim leers |
| #9 | 972344-8.patch | 2.9 KB | Jamie Holly |
| #7 | 972344-7.patch | 2.91 KB | Jamie Holly |
| #6 | 972344-6.patch | 2.88 KB | wim leers |
Comments
Comment #1
wim leersInteresting. The code for this comes from the Parallel module, so it probably was broken there as well.
I'll review this soon.
Comment #2
Jamie Holly commentedHmmm just playing around real quick, this could be handled with a preg_replace:
Set $cdn to the CDN URL. In my testing I also added '/' in the root (plus added the trailing slash to $base_url). That then grabbed non absolute images (ie: /sites/default/files) and changed them to the right CDN url. It also captures the image source if it's wrapped in single or double quotes.
Comment #3
wim leersCould you maybe roll a patch? That'd make it easier to review :)
Comment #4
Jamie Holly commentedHere's the patch. I modified it from my original idea some. I went ahead and did it with a preg_match_callback so that we can still run hook_file_url on each image. I've tested it in a few posts and it seems to be working fine on root-relative and absolute URLs, plus it keeps all the other attributes in there.
Comment #5
wim leersI don't like the direction you went with your patch. I want a single function that does the file URL altering, not two.
Patch attached. Please test and report back.
Comment #6
wim leersMinor update to the patch: now also appending the slash to the $base_url, as you were doing.
Comment #7
Jamie Holly commentedIt wasn't grabbing root-relative images and it also wasn't grabbing src attributes enclosed with a single quote. It took some playing with the regex pattern, but this patch seems to be getting it all now.
Comment #8
wim leersWhat module is so messed up that it generates src attributes with a single quote?
Why are you adding the
(.*?)near the end of the regular expression? To support root-relative URLs? I can't think of anything else. That's not so clean. Please change the value of the $root value to support root-relative URLs.Comment #9
Jamie Holly commentedIt's not a module that's generating single quotes around attributes, it's from people entering them that way. Single quotes are legal around attributes (src), so IMHO it would be best to catch those as well.
I reworked the pattern some, dropping/combining groups. It cut it from 9 groups to 5, so that should be a nice improvement. I don't see much way to make it any smaller and still be able to catch everything.
As far as root-relative paths, it's catching them for me. I did have one problem, but that is unrelated and should probably be a new issue. I uploaded one image that had an upper case extension on it. Perhaps we should to a strtolower() on the extension/key in _cdn_basic_parse_raw_mapping() and then do another on $file_extension in cdn_basic_get_servers()?
I checked the logs on a live site I put the patch on last night and the only images coming off the main server were those with weird casing in the extensions.
Comment #10
wim leersFair enough.
I've refactored a combination of my code and your code that now checks for root-relative URLs in the manner that I asked you in #8.
Please review the attached patch.
I've created a new issue for your (valid) concerns regarding extension filtering and case sensitivity: #974992: File extension filtering in Origin Pull mode is case-sensitive.
Comment #11
wim leersNew version of the patch. Identical functionality as in #10, but now with some refactoring to allow #971712: Rewrite image URLs in the node body to use this functionality without code duplication.
Comment #12
wim leersBetter title.
Comment #13
Jamie Holly commentedJust gave it a good testing and all seems to be working very well!
Comment #14
wim leersThanks for the review, committed! :)
http://drupal.org/cvs?commit=452958