Skip to content
Snippets Groups Projects
Commit 628e335c authored by Oliver Hader's avatar Oliver Hader Committed by Oliver Hader
Browse files

[BUGFIX] Apply previous site identifier as fallback for URL resolving

Prior to #93240 URL routes were reverse sorted using the corresponding
site identifier (which did not contain any URL information). For the
scenario of matching undefined URLs (e.g. base URL is "/website/", but
request was like "https://example.org/"), the first item of a reverse
sorted list was used.

Resolves: #99149
Related: #93240
Releases: main, 11.5
Change-Id: Ia242591cebfba7d8221494a5d214f6dca75a00fc
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/78794


Tested-by: default avatarOliver Hader <oliver.hader@typo3.org>
Reviewed-by: default avatarOliver Hader <oliver.hader@typo3.org>
Tested-by: default avatarcore-ci <typo3@b13.com>
parent 1c530c51
Branches
Tags
No related merge requests found
......@@ -144,6 +144,11 @@ class BestUrlMatcher extends UrlMatcher
}
// index `1` refers to the array index containing the corresponding `tail` match
// @todo not sure, whether `tail` can be defined generic, it's hard coded in `SiteMatcher`
return $b->getPathMatchScore(1) <=> $a->getPathMatchScore(1);
if ($b->getPathMatchScore(1) !== $a->getPathMatchScore(1)) {
return $b->getPathMatchScore(1) <=> $a->getPathMatchScore(1);
}
// fallback for behavior prior to issue #93240, using reverse sorted site identifier
// (side note: site identifier did not contain any URL relevant information)
return $b->getSiteIdentifier() <=> $a->getSiteIdentifier();
}
}
......@@ -18,6 +18,7 @@ declare(strict_types=1);
namespace TYPO3\CMS\Core\Routing;
use Symfony\Component\Routing\Route as SymfonyRoute;
use TYPO3\CMS\Core\Site\Entity\SiteInterface;
/**
* @internal
......@@ -84,4 +85,10 @@ class MatchedRoute
// example: complete: `/french/other`, tail: `/other` -> `strlen` of `/french`
return strpos($completeMatch, $tailMatch);
}
public function getSiteIdentifier(): string
{
$site = $this->route->getDefault('site');
return $site instanceof SiteInterface ? $site->getIdentifier() : '';
}
}
......@@ -109,9 +109,9 @@ class SiteMatcherTest extends UnitTestCase
$request = new ServerRequest('http://www.example.com/');
/** @var SiteRouteResult $result */
$result = $subject->matchRequest($request);
// Nothing found, only the empty site, but finds a random site ("main") according to the algorithm
// Nothing found, only the empty site, but finds the last site ("second") according to the algorithm
self::assertNull($result->getLanguage());
self::assertEquals('main', $result->getSite()->getIdentifier());
self::assertEquals('second', $result->getSite()->getIdentifier());
}
/**
......
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