ZF-6299: Zend_Controller_Router_Route_Static not work properly with empty _route
Description
Zend_Controller_Router_Route_Static::match
public function match($path)
{
if ($this->isPartial()) {
if (substr($path, 0, strlen($this->_route)) === $this->_route) {
$this->setMatchedPath($this->_route);
return $this->_defaults;
}
} else {
When $this->_route is empty, construction substr($path, 0, strlen($this->_route)) return "bool(false)" and condition If is not fullfilled
Comments
Posted by Matthew Weier O'Phinney (matthew) on 2010-10-20T09:42:17.000+0000
Can you provide an example of when this is a problem, exactly? I'm having trouble finding a case where this would not actually be the correct and/or expected behavior.
Posted by Eugene Myazin (meniam) on 2010-10-20T12:07:18.000+0000
When default router disabled and path '/' should point to the non default IndexController::indexAction following occurs:
I add route:
$router->addRoute( 'index', new Zend_Controller_Router_Route_Static('/', array('controller' => 'user', 'action' => 'info')) );
Zend_Controller_Router_Route_Static::_construct do:
public function __construct($route, $defaults = array()) { $this->_route = trim($route, '/'); $this->_defaults = (array) $defaults;
}
Afther that we have empty string in $this->_route
Then in match
if (substr($path, 0, strlen($this->_route)) === $this->_route) {
It's wrong condition, mistake in "==="
Other example illustrate the problem:
<?php
$path = '/';
// $test = trim($path, '/'); var_dump($test);
// $result = substr($test, 0, strlen($test)); var_dump($result);
/** * Wrong way */ if ($result === $test) { echo "Work"; } else { echo "Don't work"; }
/** * Right way */ if ($result == $test) { echo "Work"; } else { echo "Don't work"; }
PS: Sorry for my enlish, code speaks better :)
Posted by Kim Blomqvist (kblomqvist) on 2010-10-21T08:55:35.000+0000
The if() clause presented here has been commented out in the present version of trunk. I think this is not an issue anymore as the ZF-7848 has fixed.
Posted by Matthew Weier O'Phinney (matthew) on 2010-10-21T09:12:50.000+0000
Yeah -- removed that from trunk and 1.11 release branch now. That was the original clause; the new clause is what solves the issue.