Commit 5850cf73 authored by Kevin Ditscheid's avatar Kevin Ditscheid

[BUGFIX] Fix regex redirects

parent 9c536da4
......@@ -125,14 +125,26 @@ class RedirectResolver implements MiddlewareInterface {
$uri = $uri->withQuery(GeneralUtility::implodeArrayForUrl('', $requestParameters));
}
if (\preg_match($pattern, \rawurldecode($uri))) {
$uri = $uri->withHost('')->withScheme(NULL);
if (\preg_match($pattern, (string) $uri)) {
$redirectUri = \preg_replace(
$pattern, $redirect['destination_url'], \rawurldecode($uri)
);
$this->logRedirect(
$redirect, \rawurldecode($uri), $redirectUri, $start, \microtime(TRUE)
$pattern, $redirect['destination_url'], (string) $uri
);
return new RedirectResponse($redirectUri, $redirect['redirect_code']);
$redirectUri = $this->getRedirectUrl($redirectUri, $requestParameters);
if ($redirectUri === '') {
// the page either does not exist or isn't accessible, drop out
return GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
$request,
'The page with id #' . $redirect['destination_url'] . ' could not be found!',
['code' => PageAccessFailureReasons::PAGE_NOT_FOUND]
);
} else {
$this->logRedirect(
$redirect, (string) $uri, $redirectUri, $start, \microtime(TRUE)
);
return new RedirectResponse($redirectUri, $redirect['redirect_code']);
}
}
} else {
$sourceUrl = new Uri($redirect['source_url']);
......@@ -151,31 +163,19 @@ class RedirectResolver implements MiddlewareInterface {
\mb_strtolower($uri) === \mb_strtolower($sourceUrl)
)
) {
$destinationUrl = $redirect['destination_url'];
if (\strpos($destinationUrl, self::URL_WIZARD_ID) === 0) {
$destinationUrl = (int) \substr($destinationUrl, 14);
}
if (\is_numeric($destinationUrl)) {
$GLOBALS['TSFE']->sys_page = GeneralUtility::makeInstance(PageRepository::class);
$contentObjectRenderer = GeneralUtility::makeInstance(ContentObjectRenderer::class, $GLOBALS['TSFE']);
$redirectUri = $contentObjectRenderer->typoLink_URL([
'parameter' => $destinationUrl,
'additionalParams' => '&' . \implode('&', $requestParameters)
]);
if ($redirectUri === '') {
// the page either does not exist or isn't accessible, drop out
return GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
$request,
'The page with id #' . $destinationUrl . ' could not be found!',
['code' => PageAccessFailureReasons::PAGE_NOT_FOUND]
);
} else {
$this->logRedirect(
$redirect, \rawurldecode($uri), $redirectUri, $start, \microtime(TRUE)
);
return new RedirectResponse($redirectUri, $redirect['redirect_code']);
}
$redirectUri = $this->getRedirectUrl($redirect, $requestParameters);
if ($redirectUri === '') {
// the page either does not exist or isn't accessible, drop out
return GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
$request,
'The page with id #' . $redirect['destination_url'] . ' could not be found!',
['code' => PageAccessFailureReasons::PAGE_NOT_FOUND]
);
} else {
$this->logRedirect(
$redirect, (string) $uri, $redirectUri, $start, \microtime(TRUE)
);
return new RedirectResponse($redirectUri, $redirect['redirect_code']);
}
}
}
......@@ -185,7 +185,28 @@ class RedirectResolver implements MiddlewareInterface {
return $handler->handle($request);
}
/**
* Get the redirect url from typolink if necessary
*
* @param $destinationUrl
* @param $requestParameters
* @return string
*/
protected function getRedirectUrl($destinationUrl, $requestParameters): string {
if (\strpos($destinationUrl, self::URL_WIZARD_ID) === 0) {
$destinationUrl = (int) \substr($destinationUrl, 14);
}
if (\is_numeric($destinationUrl)) {
$GLOBALS['TSFE']->sys_page = GeneralUtility::makeInstance(PageRepository::class);
$contentObjectRenderer = GeneralUtility::makeInstance(ContentObjectRenderer::class, $GLOBALS['TSFE']);
$redirectUri = $contentObjectRenderer->typoLink_URL([
'parameter' => $destinationUrl,
'additionalParams' => '&' . \implode('&', $requestParameters)
]);
}
return $redirectUri ?? $destinationUrl;
}
/**
* @param array $routeRow
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment