Skip to content

Commit a5c759c

Browse files
[Routing] Prevent some double match of hosts
1 parent 3180327 commit a5c759c

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

Matcher/Dumper/PhpMatcherDumper.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ private function compileStaticRoutes(array $staticRoutes, bool $supportsRedirect
239239

240240
$code .= sprintf(" case %s:\n", self::export($url));
241241
foreach ($routes as $name => list($hasTrailingSlash, $route)) {
242-
$code .= $this->compileRoute($route, $name, $supportsRedirections, $hasTrailingSlash);
242+
$code .= $this->compileRoute($route, $name, $supportsRedirections, $hasTrailingSlash, true);
243243
}
244244
$code .= " break;\n";
245245
}
@@ -451,7 +451,7 @@ private function compileStaticPrefixCollection(StaticPrefixCollection $tree, \st
451451
$hasTrailingSlash = $state->supportsRedirections && '' !== $regex && '/' === $regex[-1];
452452

453453
if ($compiledRoute->getRegex() === $prevRegex) {
454-
$state->switch = substr_replace($state->switch, $this->compileRoute($route, $name, $state->supportsRedirections, $hasTrailingSlash)."\n", -19, 0);
454+
$state->switch = substr_replace($state->switch, $this->compileRoute($route, $name, $state->supportsRedirections, $hasTrailingSlash, false)."\n", -19, 0);
455455
continue;
456456
}
457457

@@ -485,7 +485,7 @@ private function compileStaticPrefixCollection(StaticPrefixCollection $tree, \st
485485

486486
$state->switch .= <<<EOF
487487
case {$state->mark}:
488-
{$combine}{$this->compileRoute($route, $name, $state->supportsRedirections, $hasTrailingSlash)}
488+
{$combine}{$this->compileRoute($route, $name, $state->supportsRedirections, $hasTrailingSlash, false)}
489489
break;
490490
491491
EOF;
@@ -572,16 +572,9 @@ private function compileSwitchDefault(bool $hasVars, string $routesKey, bool $ma
572572
/**
573573
* Compiles a single Route to PHP code used to match it against the path info.
574574
*
575-
* @param Route $route A Route instance
576-
* @param string $name The name of the Route
577-
* @param bool $supportsRedirections Whether redirections are supported by the base class
578-
* @param bool $hasTrailingSlash Whether the path has a trailing slash
579-
*
580-
* @return string PHP code
581-
*
582575
* @throws \LogicException
583576
*/
584-
private function compileRoute(Route $route, string $name, bool $supportsRedirections, bool $hasTrailingSlash): string
577+
private function compileRoute(Route $route, string $name, bool $supportsRedirections, bool $hasTrailingSlash, bool $checkHost): string
585578
{
586579
$code = '';
587580
$compiledRoute = $route->compile();
@@ -605,7 +598,7 @@ private function compileRoute(Route $route, string $name, bool $supportsRedirect
605598
$conditions[] = $expression;
606599
}
607600

608-
if (!$compiledRoute->getHostRegex()) {
601+
if (!$checkHost || !$compiledRoute->getHostRegex()) {
609602
// no-op
610603
} elseif ($hostMatches) {
611604
$conditions[] = sprintf('preg_match(%s, $host, $hostMatches)', self::export($compiledRoute->getHostRegex()));

0 commit comments

Comments
 (0)