Issue Type: Bug Created: 2008-05-07T08:59:25.000+0000 Last Updated: 2008-09-02T10:39:28.000+0000 Status: Resolved Fix version(s): - 1.6.0 (02/Sep/08)
Reporter: Christer Edvartsen (cogo) Assignee: Michal Minicki (martel) Tags: - Zend_Controller
Related issues: - ZF-2896
Attachments: - route.patch
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.
Posted by Christer Edvartsen (cogo) on 2008-05-07T09:02:49.000+0000
The patch is made against the official 1.5.1 release.
Posted by Christer Edvartsen (cogo) on 2008-05-08T00:35:28.000+0000
The patch does not fix the problem, so it can be deleted. The following seems to be more correct:
$values = array();
$values[$name] = $pathPart;
$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.
Posted by Michal Minicki (martel) on 2008-05-08T09:39:25.000+0000
Fixed. Thanks, Christer.
Posted by Wil Sinclair (wil) on 2008-09-02T10:39:28.000+0000
Updating for the 1.6.0 release.
Have you found an issue?
See the Overview section for more details.