Issues

ZF-8594: Zend_Controller_Router_Rewrite doesn't throw an exception when not route matches

Description

In the interface definition of the router it is stated that an exception should be thrown when no route matches the request. Instead it is currently simply ignored, which leads the request to the default controller/action, instead of going to the error controller which could emit a 404 error then. This can surely only happen, when the default module route was removed, which is intendend when you only want your own routes to match to avoid duplicate content for search engines.

Comments

I've attached a patch for this issue, but there's a problem. By applying this patch, the following two tests in Zend_Controller_Router_RewriteTest are breaking:

  1. testRouteNotMatches: Expects the route() method to return an unchanged request object, which has NULL as controller, action and module set. This will lead the front controller to dispatch the standard parameters (default/index/index), which is the actual issue we want to solve tho. So rewriting this test would actually be the test for the new (correct) behaviour.

  2. testRemoveDefaultRoutes: This one doesn't like that much like a problem, since the routing is not tested at all here, while there's still a not-tested call done to the route() method (which would usually add a default route if not disabled). This means we would just have to wrap a try {} around the route() call, and the test would suceed again. This shouldn't affect reallife applications, since there will never be no routes, and if, they should lead to the error controller.

Attached new patch which solves the problem with front controller and error handler plugin.

Assigned to Matthew for review.

Well, the assumption is incorrect.

I've used the default route in a chain, and that stopped working now.

Example.

host/AppPath/MyOwnFirstRouteThing/the/default/routing/should/apply

Either this fix is wrong, since the old behaviour was actually just like I expected it to work, or my approach is wrong and can be achieved otherwise. Maybe force default values to the 'default' route.

Peter, can you please tell, how exacly your chain setup looked (code?). The changes of this issue should not have affected stuff like you show here.

Yeah, based on the initial 'bug' and fix I also thought this would not affect stuff. However (and my chain is rather simple) it appears to influence some behaviour (maybe the problem lies within the incorrect chaining of the 'default' route... either way, below the code that fails (two methods to create the default route chained behind my own initial route included, both fail)

Maybe the matching algorithm of a default route doesn't return that it matched anything when chained this way??

    // START CREATION OF OUR OWN SPECIALIZED ROUTER
    // *************

    $router = Zend_Controller_Front::getInstance()->getRouter();

    // Create a very simple DB route that just matches the first part
    $route = new Zend_Controller_Router_Route(':db');

    // Create the 'default' route, it needs the dispatcher to function
    $default = new Zend_Controller_Router_Rewrite();
    $default = $default->addDefaultRoutes()->getRoute('default');

    //Other method to create the default route (neither works)
    /*
    $request = Zend_Controller_Front::getInstance()->getRequest();
    $dispatcher = Zend_Controller_Front::getInstance()->getDispatcher();
    //$dispatcher = null;
    $default = new Zend_Controller_Router_Route_Module(array(), $dispatcher, $request);
    */

    // Create a chained route which should match <a rel="nofollow" href="http://foo.bar/basePath/DBVARIABLE[/[module]/controller">http://foo.bar/basePath/DBVARIABLE[/&hellip;</a>....]
    $chain = $route->chain($default);
    $router->addRoute('default', $chain);
    // *************
    // THE CREATION OF THE ROUTE ENDS HERE, however we continue below with some other init stuff

There already is a unittest covering exacly your example (tho using a static route, not a segment route):

Zend_Controller_Router_Route_ChainTest::testChainingModule()

Even modified to use a segment route instead it still passes, so it is most likely a problem with your setup. For further help, please ask in irc (freenode, #zftalk) or on the mailing list.

Ah, using Zend_Controller_Router_Route_Module() instead of extracting the 'default' works like it should. Next time I'll take a look at the unit tests first...

Although I'd still call it an regression issue :D

Hmm, I might have been a bit too optimistic about this... Still experiencing problems, I forgot to revert the quickfix I had done so it wouldn't throw the error.

I'll get back on this one.

The problem already existed in Chain but surfaced due to this fix. I've created a new issue for this one; ZF-9030