Skip to content

Commit

Permalink
[BUGFIX] Don't include path for fragment-only links
Browse files Browse the repository at this point in the history
This adds a similar condition that already existed in the old link
generation for the new routing-based link building. The conditions are
adjusted accordingly.

Change-Id: I467f0ce9695fd33ab1e1545e1ba0728c037d3e93
Resolves: #89068
Releases: master, 9.5
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63909
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
  • Loading branch information
andreaswolf authored and ervaude committed Mar 27, 2020
1 parent 514388e commit 567f38e
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions typo3/sysext/frontend/Classes/Typolink/PageLinkBuilder.php
Expand Up @@ -25,6 +25,7 @@
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Exception\Page\RootLineException;
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
use TYPO3\CMS\Core\Http\Uri;
use TYPO3\CMS\Core\Routing\InvalidRouteArgumentsException;
use TYPO3\CMS\Core\Routing\RouterInterface;
use TYPO3\CMS\Core\Routing\SiteMatcher;
Expand Down Expand Up @@ -414,21 +415,33 @@ protected function generateUrlForPageWithSiteConfiguration(array $page, Site $si
$queryParameters['no_cache'] = 1;
}

try {
$uri = $siteOfTargetPage->getRouter()->generateUri(
$targetPageId,
$queryParameters,
$fragment,
$useAbsoluteUrl ? RouterInterface::ABSOLUTE_URL : RouterInterface::ABSOLUTE_PATH
);
} 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';
$uri = $uri->withScheme($scheme);
if ($fragment
&& $useAbsoluteUrl === false
&& $currentSiteLanguage === $siteLanguageOfTargetPage
&& $targetPageId === (int)$GLOBALS['TSFE']->id
&& (empty($conf['addQueryString']) || !isset($conf['addQueryString.']))
&& !$GLOBALS['TSFE']->config['config']['baseURL']
&& count($queryParameters) === 1 // _language is always set
) {
$uri = (new Uri())->withFragment($fragment);
} else {
try {
$uri = $siteOfTargetPage->getRouter()->generateUri(
$targetPageId,
$queryParameters,
$fragment,
$useAbsoluteUrl ? RouterInterface::ABSOLUTE_URL : RouterInterface::ABSOLUTE_PATH
);
} 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';
$uri = $uri->withScheme($scheme);
}
}

return $uri;
}

Expand Down

0 comments on commit 567f38e

Please sign in to comment.