Issue

ZF-11121: route variable consumed by an unmatched route

Issue Type: Bug Created: 2011-02-28T09:12:50.000+0000 Last Updated: 2012-05-11T16:29:04.000+0000 Status: Open Fix version(s): Reporter: Guillaume ORIOL (goriol) Assignee: Ben Scholzen (dasprid) Tags: - Zend_Controller_Router

Related issues: Attachments:

Description

Let's consider this router configuration:

<pre class="highlight">
$defaultRoute = new Zend_Controller_Router_Route(
    ':account/:module/:controller/:action/*',
    array(
        'account'    => 'demo',
        'module'     => 'default',
        'controller' => 'index',
        'action'     => 'index'
    ),
    array('account' => '[a-z0-9]+')
);
$router->addRoute('default', $defaultRoute);

$restRoute = new Zend_Rest_Route($front, array(), array('rest'));
$accountRoute = new Zend_Controller_Router_Route(
    ':account',
    array('account' => 'demo'),
    array('account' => '[a-z0-9]+')
);
$router->addRoute('rest', $accountRoute->chain($restRoute));

And consider the following URL: ```

The 'rest' route will be selected first. 'customer1' will properly be identified by the $accountRoute of the chain as the account and 'default' will not match against the value 'rest' of the $restRoute. Up to now, everything is fine.

Then, the 'default' route will be selected. But only the subpath 'default/invoice/index' will be passed to it as the chain consumes the matched part of its child routes (when they match) and never restore them if a subsequent route doesn't match. Hence the parameters identification will be erroneous.

Won't you consider this a bug?

Comments

Posted by Christian O. Andersson (coa) on 2012-05-11T16:29:04.000+0000

I would definitely consider this a bug.

Suggested fix:

<pre class="highlight">
*** Chain.php.original  2012-05-11 18:10:41.000000000 +0200
--- library/Zend/Controller/Router/Route/Chain.php  2012-05-11 18:20:02.000000000 +0200
***************
*** 72,77 ****
--- 72,78 ----
       */
      public function match($request, $partial = null)
      {
+         $mutatedRequest = clone($request);
          $path    = trim($request->getPathInfo(), self::URI_DELIMITER);
          $subPath = $path;
          $values  = array();
***************
*** 95,102 ****
              if (!method_exists($route, 'getVersion') || $route->getVersion() == 1) {
                  $match = $subPath;
              } else {
!                 $request->setPathInfo($subPath);
!                 $match = $request;
              }
  
              $res = $route->match($match, true);
--- 96,103 ----
              if (!method_exists($route, 'getVersion') || $route->getVersion() == 1) {
                  $match = $subPath;
              } else {
!                 $mutatedRequest->setPathInfo($subPath);
!                 $match = $mutatedRequest;
              }
  
              $res = $route->match($match, true);

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2019 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts