Skip to content

Commit 72df484

Browse files
committed
replace request target with path
1 parent 52c96ba commit 72df484

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

src/RouteMatcher.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,15 @@ public function __construct(RoutesByNameInterface $routes, ?string $cacheFile =
3232
public function match(ServerRequestInterface $request): RouteInterface
3333
{
3434
$method = $request->getMethod();
35-
$path = rawurldecode($request->getUri()->getPath());
35+
$path = $request->getUri()->getPath();
3636

37-
$routeInfo = $this->dispatcher->dispatch($method, $path);
37+
$routeInfo = $this->dispatcher->dispatch($method, rawurldecode($path));
3838

3939
if (Dispatcher::NOT_FOUND === $routeInfo[0]) {
4040
throw HttpException::createNotFound([
4141
'detail' => \sprintf(
42-
'The page "%s" you are looking for could not be found.'
43-
.' Check the address bar to ensure your URL is spelled correctly.',
44-
$request->getRequestTarget()
42+
'The path "%s" you are looking for could not be found.',
43+
$path
4544
),
4645
]);
4746
}
@@ -51,7 +50,7 @@ public function match(ServerRequestInterface $request): RouteInterface
5150
'detail' => \sprintf(
5251
'Method "%s" at path "%s" is not allowed. Must be one of: "%s"',
5352
$method,
54-
$request->getRequestTarget(),
53+
$path,
5554
implode('", "', $routeInfo[1]),
5655
),
5756
]);

tests/Integration/RouteMatcherTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static function (ServerRequestInterface $request) use ($responseFactory) {
9595

9696
self::assertSame(404, $response->getStatusCode());
9797
self::assertStringContainsString(
98-
'The page "/hello" you are looking for could not be found.',
98+
'The path "/hello" you are looking for could not be found.',
9999
(string) $response->getBody()
100100
);
101101
}

tests/Unit/RouteMatcherTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ public function testMatchNotFound(): void
8585
$request = $builder->create(ServerRequestInterface::class, [
8686
new WithReturn('getMethod', [], 'GET'),
8787
new WithReturn('getUri', [], $uri),
88-
new WithReturn('getRequestTarget', [], '/'),
8988
]);
9089

9190
/** @var RouteInterface $route */
@@ -112,7 +111,7 @@ public function testMatchNotFound(): void
112111
'type' => 'https://datatracker.ietf.org/doc/html/rfc2616#section-10.4.5',
113112
'status' => 404,
114113
'title' => 'Not Found',
115-
'detail' => 'The page "/" you are looking for could not be found. Check the address bar to ensure your URL is spelled correctly.',
114+
'detail' => 'The path "/" you are looking for could not be found.',
116115
'instance' => null,
117116
], $e->jsonSerialize());
118117
}
@@ -131,7 +130,6 @@ public function testMatchMethodNotAllowed(): void
131130
$request = $builder->create(ServerRequestInterface::class, [
132131
new WithReturn('getMethod', [], 'POST'),
133132
new WithReturn('getUri', [], $uri),
134-
new WithReturn('getRequestTarget', [], '/api/pets?offset=1&limit=20'),
135133
]);
136134

137135
/** @var RouteInterface $route */
@@ -158,7 +156,7 @@ public function testMatchMethodNotAllowed(): void
158156
'type' => 'https://datatracker.ietf.org/doc/html/rfc2616#section-10.4.6',
159157
'status' => 405,
160158
'title' => 'Method Not Allowed',
161-
'detail' => 'Method "POST" at path "/api/pets?offset=1&limit=20" is not allowed. Must be one of: "GET"',
159+
'detail' => 'Method "POST" at path "/api/pets" is not allowed. Must be one of: "GET"',
162160
'instance' => null,
163161
], $e->jsonSerialize());
164162
}
@@ -177,7 +175,6 @@ public function testMatchWithTokensNotMatch(): void
177175
$request = $builder->create(ServerRequestInterface::class, [
178176
new WithReturn('getMethod', [], 'GET'),
179177
new WithReturn('getUri', [], $uri),
180-
new WithReturn('getRequestTarget', [], '/api/pets/1'),
181178
]);
182179

183180
/** @var RouteInterface $route */
@@ -204,7 +201,7 @@ public function testMatchWithTokensNotMatch(): void
204201
'type' => 'https://datatracker.ietf.org/doc/html/rfc2616#section-10.4.5',
205202
'status' => 404,
206203
'title' => 'Not Found',
207-
'detail' => 'The page "/api/pets/1" you are looking for could not be found. Check the address bar to ensure your URL is spelled correctly.',
204+
'detail' => 'The path "/api/pets/1" you are looking for could not be found.',
208205
'instance' => null,
209206
], $e->jsonSerialize());
210207
}

0 commit comments

Comments
 (0)