diff --git a/src/Routing/Router.php b/src/Routing/Router.php index 2743c76..3160709 100644 --- a/src/Routing/Router.php +++ b/src/Routing/Router.php @@ -77,7 +77,8 @@ class Router implements RouterInterface public function dispatch(ServerRequestInterface $request, ResponseInterface $response, $next) { - $requestTarget = $request->getRequestTarget(); + // Use only the path for routing. + $requestTarget = parse_url($request->getRequestTarget(), PHP_URL_PATH); $route = $this->getStaticRoute($requestTarget); if ($route) { diff --git a/test/tests/unit/Routing/RouterTest.php b/test/tests/unit/Routing/RouterTest.php index aea9d81..24ebab4 100644 --- a/test/tests/unit/Routing/RouterTest.php +++ b/test/tests/unit/Routing/RouterTest.php @@ -363,6 +363,25 @@ class RouterTest extends \PHPUnit_Framework_TestCase $this->request->withAttribute("pathVariables", $variables)->shouldHaveBeenCalled(); } + /** + * @covers ::dispatch + * @covers ::registerRouteForTarget + */ + public function testMatchesPathAgainstRouteWithoutQuery() + { + $target = "/my/path?cat=molly&dog=bear"; + + $this->request->getRequestTarget()->willReturn($target); + $this->route->getTarget()->willReturn($target); + $this->route->getType()->willReturn(RouteInterface::TYPE_PATTERN); + $this->route->matchesRequestTarget(Argument::cetera())->willReturn(true); + + $this->router->register("GET", $target, "middleware"); + $this->router->dispatch($this->request->reveal(), $this->response->reveal(), $this->next); + + $this->route->matchesRequestTarget("/my/path")->shouldHaveBeenCalled(); + } + // ------------------------------------------------------------------------ // No Matching Routes