-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed as not planned
Closed as not planned
Copy link
Description
Symfony version(s) affected
7.3.2
Description
When there are "host tokens" (see code below), the output of the Twig templates path()
and url()
is the same, which is highly unintuitive.
symfony/src/Symfony/Component/Routing/Generator/UrlGenerator.php
Lines 212 to 239 in dff83bc
if ($hostTokens) { | |
$routeHost = ''; | |
foreach ($hostTokens as $token) { | |
if ('variable' === $token[0]) { | |
// check requirement (while ignoring look-around patterns) | |
if (null !== $this->strictRequirements && !preg_match('#^'.preg_replace('/\(\?(?:=|<=|!|<!)((?:[^()\\\\]+|\\\\.|\((?1)\))*)\)/', '', $token[2]).'$#i'.(empty($token[4]) ? '' : 'u'), $mergedParams[$token[3]])) { | |
if ($this->strictRequirements) { | |
throw new InvalidParameterException(strtr($message, ['{parameter}' => $token[3], '{route}' => $name, '{expected}' => $token[2], '{given}' => $mergedParams[$token[3]]])); | |
} | |
$this->logger?->error($message, ['parameter' => $token[3], 'route' => $name, 'expected' => $token[2], 'given' => $mergedParams[$token[3]]]); | |
return ''; | |
} | |
$routeHost = $token[1].$mergedParams[$token[3]].$routeHost; | |
} else { | |
$routeHost = $token[1].$routeHost; | |
} | |
} | |
if ($routeHost !== $host) { | |
$host = $routeHost; | |
if (self::ABSOLUTE_URL !== $referenceType) { | |
$referenceType = self::NETWORK_PATH; | |
} | |
} | |
} |
How to reproduce
The host for the route needs to be defined with "tokens", e.g.
host: '{subdomain}.example.com'
Possible Solution
Skip this code block when resolving a path.
Additional Context
No response