Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Blocker
-
Resolution: Fixed
-
Affects Version/s: 1.7.1, 1.7.2, 1.7.3, 1.7.4, 1.7.5, 1.7.6, 1.7.7, 1.7.8, 1.8.0, 1.8.1, 1.8.2, 1.8.3, 1.8.4, 1.9.0, 1.9.1, 1.9.2, 1.9.3
-
Fix Version/s: 1.11.0
-
Component/s: Zend_Controller
-
Labels:None
Description
The following is suggested in docs:
$hostnameRoute = new Zend_Controller_Router_Route_Hostname( ':username.users.example.com', array( 'controller' => 'profile', 'action' => 'userinfo' ) ); $plainPathRoute = new Zend_Controller_Router_Route_Static(''); $router->addRoute('user', $hostnameRoute->chain($plainPathRoute);
The purpose of $plainPathRoute: to create a default route for users visiting the hostname *.users.example.com.
Unfortunatelly this will never work, because static route of [empty string] will never match(). Unfortunatelly, leaving only the Route_Hostname is not an option - because as stated in the manual, lone Route_Hostname will catch each and every request
.
The bug is here: (line 78 in Zend/Controller/Router/Route/Static.php)
Zend/Controller/Router/Route/Static.php:76
public function match($path, $partial = false) { if ($partial) { if (substr($path, 0, strlen($this->_route)) === $this->_route) { $this->setMatchedPath($this->_route); return $this->_defaults; } } else { if (trim($path, '/') == $this->_route) { return $this->_defaults; } }
Why? substr() of empty string always returns false - thus this route will never match and the whole chain is ommited.
Fix:
FIX FOR Zend/Controller/Router/Route/Static.php:76
public function match($path, $partial = false) { if ($partial) { if (($this->_route === '' && $path === '') || substr($path, 0, strlen($this->_route)) === $this->_route) { $this->setMatchedPath($this->_route); return $this->_defaults; } } else { if (($this->_route === '' && $path === '') || trim($path, '/') == $this->_route) { return $this->_defaults; } }
Issue Links
| This issue duplicates: | ||||
| ZF-6299 | Zend_Controller_Router_Route_Static not work properly with empty _route |
|
|
|
Modified fix to work with non-partial matches.