A file called "my image.jpg" in sites/files can be accessed with the following URLs in a browser (independent of Drupal or any mod_rewrite):

  • htp://hostname/sites/files/my image.jpg
  • htp://hostname/sites/files/my%20image.jpg

It can't be accessed at this URL:

  • htp://hostname/sites/files/my+image.jpg

Apache gives a 404 and I think that's correct behaviour: plus symbols only signify encoded spaces in query strings, not in the main body of the URL.

Because l() calls url(), which calls drupal_urlencode() and thence the core PHP urlencode() function, then any links created to that file using l() will generate 404s.

Is this a case for using rawurlencode() instead, or adding extra string replacing to drupal_urlencode()?

Comments

xjessie007’s picture

Have you solved your issue, please?
For reference, I just posted a similar one here:
http://drupal.org/node/910136

xjessie007’s picture

I found the problem. This is caused by the patch located here http://drupal.org/files/issues/rawurlencode_0.patch and referenced here http://drupal.org/node/191116 (post #4).

Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.710
diff -u -r1.710 common.inc
--- includes/common.inc	4 Nov 2007 21:24:09 -0000	1.710
+++ includes/common.inc	10 Nov 2007 22:20:28 -0000
@@ -2272,10 +2272,10 @@
   if (variable_get('clean_url', '0')) {
     return str_replace(array('%2F', '%26', '%23', '//'),
                        array('/', '%2526', '%2523', '/%252F'),
-                       urlencode($text));
+                       rawurlencode($text));
   }
   else {
-    return str_replace('%2F', '/', urlencode($text));
+    return str_replace('%2F', '/', rawurlencode($text));
   }
 }

The patch is correct, but it breaks url aliases that are stored with spaces in the database on the url_alias table (spaces are not correct). Urlencode changes spaces into + signs. Rawurlencode changes spaces to %20. I do not know how to fix the whole problem correctly, but to make it at least work, changing rawurlencode back to urlencode does the trick. Drupal 7 is said to handle + signs in URL in a better way (?). I hope this helps to others. It took me 3 days to find the cause of the issue.

My site: Maxi-Pedia.com

jp.stacey’s picture

Status: Active » Closed (duplicate)

Hi xjessie007 - thanks for moving forward on this after so long. I think we ended up fixing it some other way but I can't remember now. I still think it's a problem, but I'm going to close this issue as a duplicate of #910136: Spaces throughout URLs being replaced by plus signs, not %20 as standard.