Can't match child route when root Part route is / #2701

Closed
robertbasic opened this Issue Oct 8, 2012 · 4 comments

Projects

None yet

4 participants

@robertbasic

If one creates a Part route, where the root route is simply /, and has a child route /foo, it can't match /foo, only / and //foo. If the root route is /foo, and has a child route bar, it will match /foo and /foo/bar.

$routeP = Http\Part::factory(array(
    'route' => array(
        'type' => 'literal',
        'options' => array(
            'route' => '/',
            'defaults' => array(
                'controller' => 'Application\Controller\IndexController',
                'action' => 'index'
            )
        ),
    ),
    'route_plugins' => $routePlugins,
    'may_terminate' => true,
    'child_routes' => array(
        'bar' => array(
            'type' => 'literal',
            'options' => array(
                'route' => '/bar',
                'defaults' => array(
                    'controller' => 'Application\Controller\IndexController',
                    'action' => 'bar'
                )
            )
        )
    )
));

$request = new Request();
$request->setUri('/bar');
var_dump(assert(is_null($routeP->match($request))));

$request = new Request();
$request->setUri('//bar');
var_dump(assert($routeP->match($request) instanceof Zend\Mvc\Router\Http\RouteMatch));

Setting the root route to just an empty string results in #2511

@macnibblet

I would see this as expected behavior imho, if you want to match /bar then you should not prefix bar with /

@robertbasic

You are correct. Guess I have a stupid today.

@robertbasic robertbasic closed this Oct 8, 2012
@localheinz
Zend Framework member
@juriansluiman

@localheinz you just have to name your child_route bar and not /bar. Then you can match / and /bar.

The strings are simply concatenated, so if you have a parent / and child /bar, the result is //bar and not /bar. If you want to have a root route / and a child route that results in /bar, subtract the / from /bar and you got bar. Thus bar is your child route.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment