Skip to content

Commit

Permalink
[BUGFIX] Apply typolink.forceAbsoluteUrl to absolute path URIs
Browse files Browse the repository at this point in the history
Due to #101083 absolute path URIs like `/path/some-file.png`
are handled as external URL, which leads to scenarios, that
the fully qualified domain name is not applied anymore, when
using `typolink.forceAbsoluteUrl=1`.

Resolves: #101709
Related: #101083
Releases: main, 12.4
Change-Id: Ie4fe94169c4ab78dd61d2b228a684f1521337fc7
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/80663
Tested-by: core-ci <typo3@b13.com>
Tested-by: Oliver Hader <oliver.hader@typo3.org>
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
  • Loading branch information
ohader committed Aug 23, 2023
1 parent 39bf11f commit 5e4b615
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Expand Up @@ -17,7 +17,11 @@

namespace TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Link;

use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Routing\PageArguments;
use TYPO3\CMS\Core\Site\Entity\Site;
use TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextFactory;
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
Expand All @@ -43,6 +47,23 @@ final class TypolinkViewHelperTest extends FunctionalTestCase
],
];

protected function setUp(): void
{
parent::setUp();
$request = new ServerRequest('http://localhost/');
$request = $request->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE);
$request = $request->withAttribute('routing', new PageArguments(1, '0', []));
$request = $request->withAttribute('site', new Site(
'site',
1,
[
'base' => 'http://localhost/',
'languages' => [],
]
));
$GLOBALS['TYPO3_REQUEST'] = $request;
}

public static function renderDataProvider(): array
{
return [
Expand Down
Expand Up @@ -27,6 +27,10 @@ class ExternalUrlLinkBuilder extends AbstractTypolinkBuilder
public function build(array &$linkDetails, string $linkText, string $target, array $conf): LinkResultInterface
{
$url = $linkDetails['url'] ?? '';
// issue https://forge.typo3.org/issues/101083 forces absolute path URLs
// like `/path/some-file.png` to be handled as external URL, and that's
// why the URL is forced to contain a fully qualified domain name as well
$url = $this->forceAbsoluteUrl($url, $conf);
$linkText = $this->encodeFallbackLinkTextIfLinkTextIsEmpty($linkText, $url);
return (new LinkResult(LinkService::TYPE_URL, (string)$url))
->withLinkConfiguration($conf)
Expand Down

0 comments on commit 5e4b615

Please sign in to comment.