Zend Framework

Zend_Controller_Router_Route_Static not work properly with empty _route

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Trivial Trivial
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 1.11.0
  • Component/s: Zend_Controller
  • Labels:
    None

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

Issue Links

Activity

Hide
Matthew Weier O'Phinney added a comment -

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.

Show
Matthew Weier O'Phinney added a comment - 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.
Hide
Eugene Myazin added a comment -

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

Show
Eugene Myazin added a comment - 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
Hide
Kim Blomqvist added a comment -

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;
            }
Show
Kim Blomqvist added a comment - 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;
            }
Hide
Matthew Weier O'Phinney added a comment -

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

Show
Matthew Weier O'Phinney added a comment - Yeah – removed that from trunk and 1.11 release branch now. That was the original clause; the new clause is what solves the issue.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: