We have a client who uploaded a few files with names like the following:
- 49ers%20mat.jpg
- bucs%20mat.jpg
- chargers%20mat.jpg
- eagles%20mat.jpg
- rams%20mat.jpg
- steelers%20mat.jpg
My guess is that when the user downloaded the images originally, they used IE, which stupidly does not url-decode the file names before providing the user with the default file name in the "Save" box.
Regardless of how the images got filenames like that, they wreak havoc with ImageCache. After uploading the images, ImageCache does not generate thumbnails and errors like the following appear in the watchdog log every time a page containing them is viewed:
- Location
- files/imagecache/uc_thumbnail/chargers%20mat.jpg
- Message
- 404: Unable to find files/chargers mat.jpg
- Severity
- error
When I renamed the files on the server, replacing "%20" with spaces, the thumbnail images displayed correctly, but then FileField produced warnings that it could no longer locate the files.
It appears that ImageCache is unescaping the filename string from what is stored in the database, which is not safe if an escape sequence is part of the filename.
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | 880098_handle_escaped_filenames_6.x-2.0-rc1.patch | 4.14 KB | lookatyeti |
| #10 | 880098_handle_escaped_filenames_2010-12-08.patch | 4.26 KB | guypaddock |
| #3 | 880098_handle_escaped_filenames.patch | 4.14 KB | guypaddock |
Comments
Comment #1
guypaddock commentedThis appears to be related to #615418: image file with '+' sign or & in name not found by imagecache.
Comment #2
guypaddock commentedAlso related to #791780: Special chars should be removed/replaced from filenames on upload..
Comment #3
guypaddock commentedAttached is a patch to correct the issue. Unlike the approach taken by similar issues, this solution does not require an .htaccess change, nor does it affect the naming of files during upload. Instead, it parses the raw image path out of the request URI, allowing the special characters in image filenames to be preserved, without Apache escaping them.
The patch was tested (and passed) with:
I wasn't able to test it with clean URLs disabled. I assume it's related to #410200: Without clean URLs ImageCache doesn't create folders or images.
Comment #4
dafederWorked for me - filenames without spaces were failing and now they work fine, no flush or cache clear necessary.
Comment #5
bluegray commentedsubscribe
Comment #6
codevoice commentedSubscribe
Comment #8
mahesh e p commented880098_handle_escaped_filenames.patch solves the problem. thanks
i couldn't review the logic. all i came up with >
why do you need "return $result;" at the end of the function _imagecache_extract_preset_and_path_from_uri(&$preset, &$path)
Comment #9
bluegray commentedI have a separate issue related to this one. A file with the name
file%20name[1].gifis uploaded. The browser requestsfile%20name%5B1%5D.gifwhich returns a not found error.I'm not sure where this should be fixed though...
Comment #10
guypaddock commentedAttached, please find a revised patch that addresses two issues with the "_imagecache_extract_preset_and_path_from_uri()" function that was provided in the original patch:
- The regular expression that extracts the file paths was not stripping the trailing query string, causing ImageCache preset previews to return 404 errors. This has been corrected so that trailing query strings are stripped.
- Removed the superfluous "return $result;" statement at the end.
If you have already applied the patch from #3, you'll need to reverse it and apply this one instead.
Comment #11
andyf commentedsubscribe
Comment #12
fizk commentedMarking as ImageCache 2.x Todo.
Comment #13
nicholasruunu commentedI'm getting the same problem with åäö, which pretty much all swedish people use.
Comment #14
arski commentedor just install transliteration module :p seems to work like magic
Comment #15
lookatyeti commentedHere is an updated patch for the 6.x-2.0-rc1 release.
Comment #16
hllvd commentedwhen you install transliteration module you execute this snipet
intead of:
I solve installing transliteration module