Skip to content

Commit

Permalink
Remove base dir from redirect urls
Browse files Browse the repository at this point in the history
Align the redirect parameter with the implementation in authentication.
Having the base path present results in a double base path.

See cakephp/authentication#343
  • Loading branch information
markstory committed Jan 25, 2020
1 parent 49bb64b commit 6fefa13
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 10 deletions.
4 changes: 0 additions & 4 deletions src/Middleware/UnauthorizedHandler/CakeRedirectHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ protected function getUrl(ServerRequestInterface $request, array $options): stri
$url = $options['url'];
if ($options['queryParam'] !== null) {
$uri = $request->getUri();
/** @psalm-suppress NoInterfaceProperties */
if (property_exists($uri, 'base')) {
$uri = $uri->withPath($uri->base . $uri->getPath());
}
$redirect = $uri->getPath();
if ($uri->getQuery()) {
$redirect .= '?' . $uri->getQuery();
Expand Down
4 changes: 0 additions & 4 deletions src/Middleware/UnauthorizedHandler/RedirectHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ protected function getUrl(ServerRequestInterface $request, array $options): stri
$url = $options['url'];
if ($options['queryParam'] !== null && $request->getMethod() === 'GET') {
$uri = $request->getUri();
/** @psalm-suppress NoInterfaceProperties */
if (property_exists($uri, 'base')) {
$uri = $uri->withPath($uri->base . $uri->getPath());
}
$redirect = $uri->getPath();
if ($uri->getQuery()) {
$redirect .= '?' . $uri->getQuery();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function testHandleRedirectWithBasePath()

$this->assertEquals(302, $response->getStatusCode());
$this->assertEquals(
'/basedir/login?redirect=%2Fbasedir%2Fadmin%2Fdashboard',
'/basedir/login?redirect=%2Fadmin%2Fdashboard',
$response->getHeaderLine('Location')
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function testHandleRedirectWithBasePath()

$this->assertEquals(302, $response->getStatusCode());
$this->assertEquals(
'/basedir/login?redirect=%2Fbasedir%2Fpath',
'/basedir/login?redirect=%2Fpath',
$response->getHeaderLine('Location')
);
}
Expand Down

0 comments on commit 6fefa13

Please sign in to comment.