diff --git a/typo3/sysext/core/Classes/Routing/BestUrlMatcher.php b/typo3/sysext/core/Classes/Routing/BestUrlMatcher.php index 415d59a627c5efeb3c18dc8e48366402b2fa1f42..fdbc376c36ddebb04487317b6ac7ddd858d3d36b 100644 --- a/typo3/sysext/core/Classes/Routing/BestUrlMatcher.php +++ b/typo3/sysext/core/Classes/Routing/BestUrlMatcher.php @@ -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(); } } diff --git a/typo3/sysext/core/Classes/Routing/MatchedRoute.php b/typo3/sysext/core/Classes/Routing/MatchedRoute.php index 19da6ac546361134604cf9dc095151bfcd4a202c..8a7209b286bfad90f6be208078ebc054a9fdece4 100644 --- a/typo3/sysext/core/Classes/Routing/MatchedRoute.php +++ b/typo3/sysext/core/Classes/Routing/MatchedRoute.php @@ -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() : ''; + } } diff --git a/typo3/sysext/core/Tests/Unit/Routing/SiteMatcherTest.php b/typo3/sysext/core/Tests/Unit/Routing/SiteMatcherTest.php index c30dd8bd605bf3a7e91cd2d73618314b6b59354b..3f79b3e4e85af620500f738da165a588c4c6bd73 100644 --- a/typo3/sysext/core/Tests/Unit/Routing/SiteMatcherTest.php +++ b/typo3/sysext/core/Tests/Unit/Routing/SiteMatcherTest.php @@ -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()); } /**