ZF-2218: Zend_View_Helper_Url and url encoding


Short summary: The parameters in Zend_View_Helper_Url are not url encoded when using the default parameters.

Long description: Today the parameters sent to Zend_View_Helper_Url are not url encoded so the programmer has to encode the parameters manually.

// route example:
// http://host/users/:user/*
// name of the route: "user"

$name = 'John Doe';

$parameters = array(
    'name' => urlencode($name) // url encode manually

echo $this->url($parameters, 'user'); // echo url

This works fine. But when I go to the generated url (http://host/users/John+Doe) and want to see his statistics, i need to add a new parameter "show" with value "statistics". New url: http://host/users/John+Doe/show/statistics.

So, standing on http://host/users/John+Doe i wouldn't have to re-send the name-parameter (John Doe) since the helper should use the current parameters as default.

$parameters = array(
    'show' => 'statistics'

echo $this->url($parameters); // generates: "http://host/users/John Doe/show/statistics" - problem is the current parameters (John Doe) is not url encoded this time (note the missing +).

Note that "John Doe" is not url encoded this time. The only workaround I've found is to always pick up the current parameters, url encode using urlencode() and re-send them all to the helper.


Commited to trunk. Thanks, Johannes.

This change breaks a lot of existing code by assuming that you WANT to encode parameters by default, contrary to prior behavior.

Hi all: Been banging my head with this one. Some of my code broke after the last update to then current CVS. Ended up being changes to the url view helper. If you pass in parameters as null, they should be removed by the assemble method (undocumented feature but I assume it's intended). however, recent changes to urlencode the urlOptions broke this behaviour. the php function urlencode returns an empty string. So the route->assemble method doesn't know anymore that it was null. I suggest the following fix:

   if ($encode) {
       foreach ($urlOptions as $key => $option) {
           if(null === $option){
               $urlOptions[$key] = $option;
               $urlOptions[$key] = urlencode($option);

Unless there is an issue with unencoded null values (which I can't picture), this should solve the issue without causing any compatibility issues.

Anybody out there that can commit this fix? Thanks,


Fixed with revision 7383. Thanks, Gunter.