Issues

ZF-8812: Zend_Controller_Router_Route_Chain fails with some combinations of routes in the chain

Issue Type: Bug Created: 2010-01-13T19:54:51.000+0000 Last Updated: 2010-10-20T11:46:52.000+0000 Status: Resolved Fix version(s): - 1.11.0 (02/Nov/10)

Reporter: Ziad (ziadx) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Controller

Related issues: - ZF-10536

Attachments: - Chain.php.diff

Description

Here are the pieces of relevant code and test cases:

<pre class="highlight">
$front = Zend_Controller_Front::getInstance();
$router = $front->getRouter();
$request = new Zend_Controller_Request_Http();
$front->setRequest($request);

$router->removeDefaultRoutes();
$languageRoute = new Zend_Controller_Router_Route_Regex('([a-z]{2})?', array('language' => 'xx'), array(1 => 'language'), '%s');
$moduleRoute = new Zend_Controller_Router_Route_Module(array(), Zend_Controller_Front::getInstance()->getDispatcher(), $request);
$defaultRoute = $languageRoute->chain($moduleRoute);
$router->addRoute('default', $defaultRoute);

Inside the match() method of Zend_Controller_Router_Route_Chain, if the request URI is '/en/' or '/en', then $subPath will become bool(false) after the match() call to the regex route. Therefore, not only will the module route never get picked up, but the match() method of the chain route will return bool(false).

I was able to patch this by changing:

<pre class="highlight">
if ($key > 0 && $matchedPath !== null) {

to

<pre class="highlight">
if ($key > 0 && $matchedPath !== null && $subPath !== '' && $subPath !== false) {

Comments

Posted by Ziad (ziadx) on 2010-01-13T19:56:17.000+0000

formatting

Posted by Matthew Weier O'Phinney (matthew) on 2010-01-14T04:40:35.000+0000

Assigning to Ben.

Posted by David Nussio (david) on 2010-01-19T00:17:28.000+0000

I'm using Ziad's patch that solve similar case.

resources.router.routes.defaultmodule.type = Zend_Controller_Router_Route_Module resources.router.routes.defaultmodule.defaults.module = "default" resources.router.routes.defaultmodule.defaults.controller = "index" resources.router.routes.defaultmodule.defaults.action = "index"

resources.router.routes.language.type = Zend_Controller_Router_Route resources.router.routes.language.route = ":language" resources.router.routes.language.reqs.language = "^(it|fr|en|de)$" resources.router.routes.language.defaults.language = "en"

resources.router.routes.default.type = Zend_Controller_Router_Route_Chain resources.router.routes.default.chain = "language, defaultmodule"

Posted by David Nussio (david) on 2010-03-03T02:44:31.000+0000

Hello, could you change the priority of this task? I have to patch every new release to do work route chain defaults value. Thanks, great work.

Posted by Kevin Horst (kevinh) on 2010-07-03T06:51:37.000+0000

also tested with 1.10.1

resources.frontcontroller.defaultModule = "default" resources.frontcontroller.controllerDirectory = APPLICATION_PATH "/controllers" resources.frontcontroller.moduleDirectory = APPLICATION_PATH "/modules"

resources.router.routes.defaultRoute.type = Zend_Controller_Router_Route_Module" resources.router.routes.defaultRoute.abstract = "On" resources.router.routes.defaultRoute.route = ":module" resources.router.routes.defaultRoute.defaults.module = "default"

resources.router.routes.language.type = "Zend_Controller_Router_Route" resources.router.routes.language.route = ":lang" resources.router.routes.language.reqs.lang = "^(en|de)$" resources.router.routes.language.defaults.lang = "en"

resources.router.routes.default.type = "Zend_Controller_Router_Route_Chain" resources.router.routes.default.chain = "language, defaultRoute"

test url -> request-object

/ -> /en/default/index/index /en -> /en/default/index/index /de -> /de/default/index/index /en/admin/index/index -> /en/admin/index/index /en/index -> /en/default/index/index

works all great. i think, this is a blocker.

Posted by Kim Blomqvist (kblomqvist) on 2010-10-09T06:13:11.000+0000

Patch and unit test added.

Posted by Kim Blomqvist (kblomqvist) on 2010-10-16T02:23:16.000+0000

To get unit test work, patch from ZF-10536 should be added first.

Posted by Matthew Weier O'Phinney (matthew) on 2010-10-20T11:46:11.000+0000

Applied to both trunk and 1.11 release branch -- thanks!

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 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