Skip to content

Commit

Permalink
refactor: Ensure that the redirect is not null before referencing it
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Sep 17, 2024
1 parent 8ce01d0 commit d24beb4
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/gql/resolvers/RetourResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,19 @@ public static function resolve(mixed $source, array $arguments, mixed $context,
Retour::$plugin->statistics->incrementStatistics($uri, false, $siteId);
}
}
$dest = $redirect['redirectDestUrl'];
// If this isn't an absolute URL, make it one based on the appropriate site
if (!UrlHelper::isAbsoluteUrl($dest)) {
try {
$dest = UrlHelper::siteUrl($dest, null, null, $siteId);
$dest = parse_url($dest, PHP_URL_PATH);
} catch (Throwable $e) {
// That's ok
if ($redirect !== null) {
$dest = $redirect['redirectDestUrl'];
// If this isn't an absolute URL, make it one based on the appropriate site
if (!UrlHelper::isAbsoluteUrl($dest)) {
try {
$dest = UrlHelper::siteUrl($dest, null, null, $siteId);
$dest = parse_url($dest, PHP_URL_PATH);
} catch (Throwable $e) {
// That's ok
}
}
$redirect['redirectDestUrl'] = $dest;
}
$redirect['redirectDestUrl'] = $dest;

return $redirect;
}
Expand Down

0 comments on commit d24beb4

Please sign in to comment.