Skip to content
Permalink
Browse files

Ensure RoutingMiddleware does not wipe off existing params keys.

Closes #10989
  • Loading branch information...
ADmad committed Aug 3, 2017
1 parent 51f9ab8 commit 11a742e3ec8cc30dac6a3aea21d9ccdd9cc55569
@@ -88,7 +88,7 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
if (is_array($parsedBody) && isset($parsedBody['_method'])) {
$request = $request->withMethod($parsedBody['_method']);
}
$params = Router::parseRequest($request);
$params = Router::parseRequest($request) + $params;
if (isset($params['_middleware'])) {
$middleware = $params['_middleware'];
unset($params['_middleware']);
@@ -105,6 +105,31 @@ public function testRouterSetParams()
$middleware($request, $response, $next);
}
/**
* Test routing middleware does wipe off existing params keys.
*
* @return void
*/
public function testPreservingExistingParams()
{
$request = ServerRequestFactory::fromGlobals(['REQUEST_URI' => '/articles']);
$request = $request->withAttribute('params', ['_csrfToken' => 'i-am-groot']);
$response = new Response();
$next = function ($req, $res) {
$expected = [
'controller' => 'Articles',
'action' => 'index',
'plugin' => null,
'pass' => [],
'_matchedRoute' => '/articles',
'_csrfToken' => 'i-am-groot'
];
$this->assertEquals($expected, $req->getAttribute('params'));
};
$middleware = new RoutingMiddleware();
$middleware($request, $response, $next);
}
/**
* Test middleware invoking hook method
*

0 comments on commit 11a742e

Please sign in to comment.
You can’t perform that action at this time.