Improve URL encoding

drumm - September 25, 2007 - 22:33
Project:Drupal
Version:6.x-dev
Component:base system
Category:bug report
Priority:normal
Assigned:drumm
Status:duplicate
Description

drupal_urlencode() does two things:

1. Changes %2F to slashes, because there is actually no reason to encode slashes.
2. Works around a mod_rewrite bug where the path, the q argument, is un-encoded before it is passed to PHP.

#2 is not relevant for the query string and should not happen there.

- drupal_url_encode() gets another argument to determine the query string or not context.
- drupal_query_string_encode() uses the new argument.
- url() gets better documentation.
- code in core is corrected to properly use these API functions.

AttachmentSizeStatusTest resultOperations
drupal_urlencode_0.patch7.06 KBIgnoredNoneNone

#1

hass - October 2, 2007 - 22:35

Is this a bugfix for the problem i reported in http://drupal.org/node/178432?

#2

moshe weitzman - October 3, 2007 - 00:48

Steven would be a great reviewer on this if available.

#3

moshe weitzman - October 26, 2007 - 17:26

Is there any example of a bug caused by this in core or contrib?

#4

drumm - November 3, 2007 - 22:25

Updated to HEAD.

What raised this issue for me was doing an autocomplete URL like http://example.com/autocomplete/string, where string was a URL with a double slash. The second slash got lost due to apache.

AttachmentSizeStatusTest resultOperations
url_encoding.patch0 bytesIgnoredNoneNone

#5

drumm - November 3, 2007 - 22:33
AttachmentSizeStatusTest resultOperations
url_encoding.patch7.47 KBIgnoredNoneNone

#6

drumm - November 5, 2007 - 06:19
AttachmentSizeStatusTest resultOperations
url_encoding.patch6.8 KBIgnoredNoneNone

#7

moshe weitzman - November 7, 2007 - 18:24
Priority:critical» normal

seems like a regular old bug to me. downgrading.

#8

hass - January 27, 2008 - 13:46

Shouldn't we get this in?

#9

Pawel Gawlowski - March 2, 2008 - 21:32

Could you apply this also to 5.x?
It works great and solves my issue http://drupal.org/node/221915

#10

jcnventura - September 1, 2008 - 14:21

Just FYI, the print module has had to create a work around around a double URL encoding that happens when using drupal_query_string_encode() #285496: Problem with drupal_query_string_encode().

João

#11

fonant - September 1, 2008 - 14:44

My vote would be for a simpler fix, leaving drupal_urlencode() as it is, but only calling it when it's actually needed. The documentation for drupal_urlencode() should make it clear that it should not be used for query string encoding.

However drupal_query_string_encode() is currently broken: it should not call drupal_urlencode() but should call rawurlencode() or urlencode() instead. This bug seems to have been introduced here: http://drupal.org/node/74070.

comment.module and update.fetch.inc also need correcting to use drupal_query_string_encode() instead of drupal_urlencode() for their query strings.

Apart from these three places, drupal_urlencode() isn't called from anywhere else in Drupal core.

#12

fonant - September 1, 2008 - 14:49

Since, in fact, the only place that Drupal core calls drupal_urlencode() correctly is within url(), perhaps the function should be removed and its code merged into the url() function?

#13

fonant - September 18, 2008 - 20:09

See a separate issue, and patch, for the double-encoding problem for query strings:
http://drupal.org/node/310139

#14

jcnventura - September 19, 2008 - 10:31

Shouldn't this be marked as a duplicate then?

I prefer the patch in #310139: drupal_query_string_encode() should not call drupal_urlencode()...

Joao

#15

pwolanin - July 1, 2009 - 13:33
Status:needs review» duplicate
 
 

Drupal is a registered trademark of Dries Buytaert.