Skip to content

Commit

Permalink
Do not decode path before matching
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Jul 4, 2024
1 parent c0434ad commit 0d6f7a3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function handleRequest(Request $request): Response
}

$method = $request->getMethod();
$path = \rawurldecode($request->getUri()->getPath());
$path = $request->getUri()->getPath();

$toMatch = "{$method}\0{$path}";

Expand All @@ -90,7 +90,7 @@ public function handleRequest(Request $request): Response
* @var array<string, string> $routeArgs
*/
[, $requestHandler, $routeArgs] = $match;
$request->setAttribute(self::class, $routeArgs);
$request->setAttribute(self::class, \array_map(\rawurldecode(...), $routeArgs));

return $requestHandler->handleRequest($request);

Expand Down
8 changes: 5 additions & 3 deletions test/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,18 @@ public function testMerge(): void

public function testPathIsMatchedDecoded(): void
{
$requestHandler = new ClosureRequestHandler(function () {
$requestHandler = new ClosureRequestHandler(function (Request $request) {
self::assertSame(['s1' => 'ba /r', 's2' => 'baΩ%'], $request->getAttribute(Router::class));

return new Response(HttpStatus::OK);
});

$router = new Router($this->server, $this->testLogger, $this->errorHandler);
$router->addRoute("GET", "/fo+ö", $requestHandler);
$router->addRoute("GET", "/fo+" . \rawurlencode("ö") . "/{s1}/{s2}", $requestHandler);

$this->server->start($router, $this->errorHandler);

$uri = "/fo+" . \rawurlencode("ö");
$uri = "/fo+" . \rawurlencode("ö") . '/' . \rawurlencode("ba /r") . '/' . \rawurlencode("baΩ%");

$request = new Request($this->createMock(Client::class), "GET", Uri\Http::createFromString($uri));
$response = $router->handleRequest($request);
Expand Down

0 comments on commit 0d6f7a3

Please sign in to comment.