From a851cb4ed39438ea2390e75bc7efedb5a5a8a60b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Wolda=C5=84ski?= Date: Thu, 14 May 2026 13:25:16 +0200 Subject: [PATCH] [BUGFIX] Do not force absolute uri for relative links Resolves: #889 --- Classes/Utility/UrlUtility.php | 6 ++++-- Tests/Unit/Utility/UrlUtilityTest.php | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Classes/Utility/UrlUtility.php b/Classes/Utility/UrlUtility.php index ddcbfdaf..66fafa25 100644 --- a/Classes/Utility/UrlUtility.php +++ b/Classes/Utility/UrlUtility.php @@ -89,7 +89,9 @@ public function getFrontendUrlWithSite($url, SiteInterface $site, string $return $this->handleLanguageConfiguration($siteLanguage, $this); } - if (!$this->headlessMode->isEnabled() || $this->alreadyFrontendLink($url)) { + $targetUri = new Uri($this->sanitizeBaseUrl($url)); + + if (!$this->headlessMode->isEnabled() || $this->alreadyFrontendLink($url) || $targetUri->getHost() === '') { return $url; } @@ -108,7 +110,7 @@ public function getFrontendUrlWithSite($url, SiteInterface $site, string $return $frontBase = $frontendBase->getHost(); $frontExtraPath = $frontendBase->getPath(); $frontPort = $frontendBase->getPort(); - $targetUri = new Uri($this->sanitizeBaseUrl($url)); + $targetUri = $targetUri->withHost($frontBase); if ($targetUri->getScheme() === '') { $targetUri = $targetUri->withScheme($frontendBase->getScheme()); diff --git a/Tests/Unit/Utility/UrlUtilityTest.php b/Tests/Unit/Utility/UrlUtilityTest.php index 9e758098..d570b563 100644 --- a/Tests/Unit/Utility/UrlUtilityTest.php +++ b/Tests/Unit/Utility/UrlUtilityTest.php @@ -242,6 +242,7 @@ public function testOptimizedUrlsForFrontendApp(): void ], ], ]); + $site->getLanguages()->willReturn([]); $resolver = $this->prophesize(Resolver::class); $resolver->evaluate(Argument::containingString('Development'))->willReturn(true); @@ -271,6 +272,12 @@ public function testOptimizedUrlsForFrontendApp(): void $urlUtility->prepareRelativeUrlIfPossible('https://test-second-frontend.tld/test-page') ); + // do not touch already relative links + self::assertSame( + '/test-page', + $urlUtility->getFrontendUrlWithSite('/test-page', $site->reveal()) + ); + // test reversed = "Testing" condition $resolver = $this->prophesize(Resolver::class); $resolver->evaluate(Argument::containingString('Development'))->willReturn(false);