Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

[Router] non existent child route during assembly doesn't throw exception #4035

Closed
wants to merge 1 commit into from

2 participants

@radnan

The router will not throw exceptions if a user tries to assemble a multi-part route where child routes don't actually exist.

So, let's say we have a valid route app/entry/view but the user assembles a route app/entry/view/foo no exceptions are thrown and the router quietly outputs the valid part of route.

@weierophinney

This actually applies to master as well, so I cherry-picked it to master and merged to both master and develop.

@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/4035'
Close #4035
95286a1
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/4035' into develop
Forward port #4035
6ef26ee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
3  library/Zend/Mvc/Router/Http/TreeRouteStack.php
@@ -188,6 +188,9 @@ public function assemble(array $params = array(), array $options = array())
}
if (isset($names[1])) {
+ if (!$route instanceof TreeRouteStack) {
+ throw new Exception\RuntimeException(sprintf('Route with name "%s" does not have child routes', $names[0]));
+ }
$options['name'] = $names[1];
} else {
unset($options['name']);
View
16 tests/ZendTest/Mvc/Router/Http/TreeRouteStackTest.php
@@ -285,6 +285,22 @@ public function testAssembleNonExistentRoute()
$stack->assemble(array(), array('name' => 'foo'));
}
+ public function testAssembleNonExistentChildRoute()
+ {
+ $this->setExpectedException('Zend\Mvc\Router\Exception\RuntimeException', 'Route with name "index" does not have child routes');
+ $stack = new TreeRouteStack();
+ $stack->addRoute(
+ 'index',
+ array(
+ 'type' => 'Literal',
+ 'options' => array(
+ 'route' => '/',
+ ),
+ )
+ );
+ $stack->assemble(array(), array('name' => 'index/foo'));
+ }
+
public function testDefaultParamIsAddedToMatch()
{
$stack = new TreeRouteStack();
Something went wrong with that request. Please try again.