Skip to content

Commit

Permalink
Allow trailing slash in root page with query param
Browse files Browse the repository at this point in the history
  • Loading branch information
danon committed Jan 25, 2024
1 parent a33d197 commit 0238d55
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/Http/Middleware/RedirectToCanonicalUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ public function handle(Request $request, callable $next): HttpFoundation\Respons

private function hasTrailingSlash(Request $request): bool
{
if ($request->getRequestUri() === '/') {
$uri = $request->getPathInfo();
if ($uri === '/') {
return false;
}
return \str_ends_with($request->getPathInfo(), '/');
return \str_ends_with($uri, '/');
}

private function hasTrailingQuerySeparator(Request $request): bool
Expand Down
8 changes: 8 additions & 0 deletions tests/Unit/Canonical/TrailingSlash/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ public function homepage()
$this->assertCanonicalGet('/');
}

/**
* @test
*/
public function homepageQueryParam()
{
$this->assertCanonicalGet('/?query=param');
}

/**
* @test
*/
Expand Down

0 comments on commit 0238d55

Please sign in to comment.