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

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.

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 :)

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.


    public function match($path, $partial = false)
    {
        if ($partial) {
-->         // if (substr($path, 0, strlen($this->_route)) === $this->_route) {
            if ((empty($path) && empty($this->_route))
                || (substr($path, 0, strlen($this->_route)) === $this->_route)
            ) {
                $this->setMatchedPath($this->_route);
                return $this->_defaults;
            }

Yeah -- removed that from trunk and 1.11 release branch now. That was the original clause; the new clause is what solves the issue.