I have a client who uploads photos with names like 800_werk%20035.jpg to his site (with image module). Uploading and storing on the server goes fine. Displaying however fails because the html reads: <img src="800_werk%20035.jpg" ...>. When the browser requests this file the server interprets it as 800_werk 035.jpg (%20 decodes as a space) and doesn't find it.
In attachment is a small patch to escape the '%' character in the file_create_url() function.
I don't now if this is the right approach, but it works for my client. Moreover I did not test it with different browsers/platforms.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | 154245_file_urlencode_04.patch | 803 bytes | soxofaan |
| #9 | 154245_file_urlencode_03.patch | 799 bytes | soxofaan |
| #6 | FILE_DOWNLOADS_PUBLIC-urlencode-file.inc_.patch | 703 bytes | toeofdestiny |
| #5 | patch_154245_2.patch | 761 bytes | soxofaan |
| #3 | patch_154245.patch | 710 bytes | soxofaan |
Comments
Comment #1
Steven commentedThis need proper urlencoding.
Comment #2
soxofaan commentedThat was also my first thought but the problem is that the slash ('/') in
images/800_werk%20035.jpgwill also be encoded, which is not desired. I guess you need to explode the path on '/' first, urlencode each part and implode again. This is probably a lot of overhead for just coping with a corner case?Comment #3
soxofaan commentedThis patch uses drupal_urlencode() instead of the hackish str_replace() of my original patch.
No problem with "/" characters in the path.
Comment #4
drummThis would double-encode the path when using the private file download method, since url() does that for us.
Comment #5
soxofaan commentedmoved it inside the FILE_DOWNLOADS_PUBLIC case branch:
At #4 where version was changed from 5.x-def to 6.x dev:
shouldn't this also be fixed in D5?
Comment #6
toeofdestiny commentedI have the same problem here, and here is my patch.
It is almost the same as the already submitted one, except that I "rawurlencode" the path because the paths containing '+' weren't working on my server for some reason.
Comment #7
drewish commentedsee #140238: can't access files with percents in filenames
Comment #8
drewish commentedactually this has a patch so i'll mark it as active instead. it'd need to be applied to 7 and then backported as a bug fix.
Comment #9
soxofaan commentedreroll for HEAD
Comment #10
soxofaan commentedreroll for the new Drupal coding standard about string concatenation I just learned about ;)
Comment #11
Freso commentedAdding to my issue queue.
Comment #12
bjaspan commentedSubscribe. It looks like my issue http://drupal.org/node/238299 may be a duplicate of this one.
Comment #13
Freso commented@bjaspan: That sounds very likely. Could you perhaps try the patch and see if it fixes the problem on your end?
Comment #14
c960657 commentedUsing drupal_urlencode() wont work for filenames containing # or & when clean_url's are enabled. I suggest using
str_replace('%2F', '/', rawurlencode($prefix . $path))instead (the same approach is used inside drupal_urlencode()).See also the patch in #207310: Allow rewriting of file URL's using custom_url_rewrite_outbound().
Comment #15
c960657 commentedClosing as duplicate of #238299: file_create_url should return valid URLs. That bug has a patch (pending review) and a unit test.
Comment #16
c960657 commented