ZF2-143: When assembling string based on routes and route parameters, an absent optional parameter throws InvalidArgumentException even when there are no child routes of the terminating route

Issue Type: Bug Created: 2012-01-20T21:29:09.000+0000 Last Updated: 2012-01-30T20:37:30.000+0000 Status: Resolved Fix version(s): Reporter: Andrew Moenk (amoenk) Assignee: Ben Scholzen (dasprid) Tags: Related issues: Attachments: - zend-mvc-router-http-part-bug.php


Zend\Mvc\Router\Http\Part::assemble (184) line sets option has_child based on if the route has a name or not, instead of whether the route has children. The has_child option set to true precludes the ability for optional route parameters to be NULL and thus excluded from the assembled route.


Posted by Andrew Moenk (amoenk) on 2012-01-20T21:30:55.000+0000

CLI issue reproduction script. Assumes its place in a project's bin/ directory.

Posted by Andrew Moenk (amoenk) on 2012-01-20T21:32:30.000+0000

Recommended patch:

diff --git a/library/Zend/Mvc/Router/Http/Part.php b/library/Zend/Mvc/Router/Http/Part.php index 255569f..8a0cfc5 100644 --- a/library/Zend/Mvc/Router/Http/Part.php +++ b/library/Zend/Mvc/Router/Http/Part.php @@ -181,7 +181,7 @@ class Part extends TreeRouteStack implements Route $this->childRoutes = null; }

  • $options['has_child'] = (isset($options['name']));

  • $options['has_child'] = ($this->childRoutes !== null);

    $path = $this->route->assemble($params, $options); $params = array_diff_key($params, array_flip($this->route->getAssembledParams()));

Have you found an issue?

See the Overview section for more details.


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

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