Skip to content

Commit

Permalink
[BUGFIX] Force scheme if forceAbsoluteUrl.scheme is set
Browse files Browse the repository at this point in the history
Allow overriding the scheme with forceAbsoluteUrl even if the page
is not protected.

Also the case is now covered where a scheme of a full URL with a path
should be changed. The path in now correctly prepended by a slash.

Resolves: #90228
Releases: master, 10.4
Change-Id: I37592838a2026ad0bed0386e44caa7ffac1fb65e
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63252
Tested-by: core-ci <typo3@b13.com>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: Richard Haeser <richard@richardhaeser.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Richard Haeser <richard@richardhaeser.com>
  • Loading branch information
nhovratov authored and haassie committed May 31, 2021
1 parent 6874ac2 commit 17d0055
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,14 @@ protected function forceAbsoluteUrl(string $url, array $configuration): string
$isUrlModified = true;
}
// Override scheme:
$forceAbsoluteUrl = &$configuration['forceAbsoluteUrl.']['scheme'];
if (!empty($forceAbsoluteUrl) && $urlParts['scheme'] !== $forceAbsoluteUrl) {
$urlParts['scheme'] = $forceAbsoluteUrl;
$forcedScheme = $configuration['forceAbsoluteUrl.']['scheme'] ?? null;
if (!empty($forcedScheme) && $urlParts['scheme'] !== $forcedScheme) {
$urlParts['scheme'] = $forcedScheme;
$isUrlModified = true;
}
// Also ensure the path has a "/" at the beginning when concatenating everything else together
if ($urlParts['path'] !== '') {
$urlParts['path'] = '/' . ltrim($urlParts['path'], '/');
$isUrlModified = true;
}
// Recreate the absolute URL:
Expand Down
6 changes: 3 additions & 3 deletions typo3/sysext/frontend/Classes/Typolink/PageLinkBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,9 @@ protected function generateUrlForPageWithSiteConfiguration(array $page, Site $si
} catch (InvalidRouteArgumentsException $e) {
throw new UnableToLinkException('The target page could not be linked. Error: ' . $e->getMessage(), 1535472406);
}
// Override scheme, but only if the site does not define a scheme yet AND the site defines a domain/host
if ($useAbsoluteUrl && !$uri->getScheme() && $uri->getHost()) {
$scheme = $conf['forceAbsoluteUrl.']['scheme'] ?? 'https';
// Override scheme if absoluteUrl is set, but only if the site defines a domain/host. Fall back to site scheme and else https.
if ($useAbsoluteUrl && $uri->getHost()) {
$scheme = $conf['forceAbsoluteUrl.']['scheme'] ?? ($uri->getScheme() ?: 'https');
$uri = $uri->withScheme($scheme);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,17 @@ public function forceAbsoluteUrlReturnsCorrectAbsoluteUrlDataProvider()
'scheme' => 'typo3'
]
]
]
],
'Scheme can be forced with full URL with path' => [
'typo3://example.org/subfolder/file.txt',
'http://example.org/subfolder/file.txt',
[
'forceAbsoluteUrl' => '1',
'forceAbsoluteUrl.' => [
'scheme' => 'typo3'
]
]
],
];
}

Expand Down

0 comments on commit 17d0055

Please sign in to comment.