Skip to content

Commit

Permalink
Fix relative front end preview links (see #6843)
Browse files Browse the repository at this point in the history
Description
-----------

For relative links, the `Uri` host would be empty, therefore it would generate a link with `localhost` instead of just keeping the relative link.

Commits
-------

f6c66d8 Fix relative frontend preview links
  • Loading branch information
aschempp committed Feb 2, 2024
1 parent 28a9092 commit cb3dde0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core-bundle/src/Controller/BackendPreviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function __invoke(Request $request): Response

$targetUri = new Uri($targetUrl);

if ($request->getHost() === $targetUri->getHost() || !($user = $this->security->getUser())) {
if (!$targetUri->getHost() || $request->getHost() === $targetUri->getHost() || !($user = $this->security->getUser())) {
return new RedirectResponse($targetUrl);
}

Expand Down
6 changes: 6 additions & 0 deletions core-bundle/tests/Controller/BackendPreviewControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ public function redirectsFromPreviewUrlConvertEventListener(): \Generator
'https://www.example.com/en/foo.html',
];

yield 'Redirect relative to front end' => [
'https://www.example.com/preview.php/contao/preview?page=17',
'/en/foo.html',
'/en/foo.html',
];

yield 'Redirects to login link URL for cross-domain previews' => [
'https://www.example.com/preview.php/contao/preview?page=42',
'https://www.example.org/en/foo.html',
Expand Down

0 comments on commit cb3dde0

Please sign in to comment.