Skip to content

Commit

Permalink
Fix failing tests.
Browse files Browse the repository at this point in the history
requests are now treated as immutable internally. If you are using
Router::parseNamedParams() you must capture the return value.
  • Loading branch information
markstory committed Dec 11, 2017
1 parent 5d13e74 commit 6987882
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Routing/Dispatcher.php
Expand Up @@ -65,7 +65,7 @@ public function dispatch(ServerRequest $request, Response $response)
);
$actionDispatcher = new ActionDispatcher(null, $this->getEventManager(), $this->_filters);
$response = $actionDispatcher->dispatch($request, $response);
if ($request->getParam('return')) {
if ($request->getParam('return', null) !== null) {
return $response->body();
}

Expand Down
9 changes: 6 additions & 3 deletions src/Routing/Router.php
Expand Up @@ -906,11 +906,12 @@ public static function parseNamedParams(ServerRequest $request, array $options =
return $request->withParam('named', []);
}
$named = [];
foreach ($request->getParam('pass') as $key => $value) {
$pass = $request->getParam('pass');
foreach ((array)$pass as $key => $value) {
if (strpos($value, $options['separator']) === false) {
continue;
}
$request = $request->withoutParam("pass.{$key}");
unset($pass[$key]);
list($key, $value) = explode($options['separator'], $value, 2);

if (preg_match_all('/\[([A-Za-z0-9_-]+)?\]/', $key, $matches, PREG_SET_ORDER)) {
Expand All @@ -932,7 +933,9 @@ public static function parseNamedParams(ServerRequest $request, array $options =
$named = array_merge_recursive($named, [$key => $value]);
}

return $request->withParam('named', $named);
return $request
->withParam('pass', $pass)
->withParam('named', $named);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Routing/RouterTest.php
Expand Up @@ -3044,7 +3044,7 @@ public function testParseNamedParameters()
'action' => 'index',
'pass' => ['home', 'one:two', 'three:four', 'five[nested][0]:six', 'five[nested][1]:seven']
]);
Router::parseNamedParams($request);
$request = Router::parseNamedParams($request);
$expected = [
'plugin' => null,
'controller' => 'posts',
Expand Down

0 comments on commit 6987882

Please sign in to comment.