ZF-3219: Issue regarding similiar routes

Description

I have experienced a problem regarding similar Zend_Controller_Router_Route routes. Lets say we have an array of routes that look like this:

array( 'newsShow' => new Zend_Controller_Router_Route('news/:id/:title', array('controller' => 'news', 'action' => 'show', 'id' => null, 'title' => null), array('id' => '\d+', 'title' => '^[a-zA-Z0-9_]+$')), 'rssNewsComments' => new Zend_Controller_Router_Route('news/:id/comments/rss', array('module' => 'rss', 'controller' => 'rss', 'action' => 'news-comments', 'id' => null), array('id' => '\d+')) );

As you can see the two routes are pretty similar. This causes a problem if the dispatcher check against the rss route before the other one. The reason is that the match method changes the route values as it goes along, and when it finds out that the current route does not match anyway it does not reset the values.

Now, this is not a big problem, except when you forget to set the values using the url helper. This is how I found out about this "problem".

When doing

<?= $this->url(array(), 'rssNewsComments') ?>

in my view the :id part of the rssNewsComments route is set even if I forgot to specify it in the array. This is because I am currently on the 'newsShow' page and the dispatcher changed the rssNewsComments route when looking for the current route. Normally this would result in an error telling me that "id is not specified".

I have a fix ready if you think this is a problem worth fixing.

Comments

The patch is made against the official 1.5.1 release.

The patch does not fix the problem, so it can be deleted. The following seems to be more correct:

135a136

    $values = array();

174c175

< $this->_values[$name] = $pathPart;

                $values[$name] = $pathPart;

184c185

< $return = $this->_values + $this->_params + $this->_defaults;

    $return = $values + $this->_params + $this->_defaults;

197a199,200 $this->_values = $values;

This simply stores the values to be set in the route in a temp array and after the loop is finished, and the last checks (which I forgot about in the patch file attached) passes we build the return value using the temp array. The last thing we do before returning is to assign the temp array to $this->_values.

This is also made against the official 1.5.1 release.

Sorry for the incorrect file attachment.

Fixed. Thanks, Christer.

Updating for the 1.6.0 release.