Skip to content

Commit 5f149da

Browse files
committed
Merge branch '4.3' into 4.4
* 4.3: [FrameworkBundle] Detect indirect env vars in routing Remove calls to deprecated function assertAttributeX [Intl] Order alpha2 to alpha3 mapping [Routing] added a warning about the getRouteCollection() method Allow sutFqcnResolver to return array [HttpFoundation] Revert getClientIp @return docblock
2 parents 75599e9 + 5bc7841 commit 5f149da

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

Routing/Router.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private function resolve($value)
160160
return '%%';
161161
}
162162

163-
if (preg_match('/^env\(\w+\)$/', $match[1])) {
163+
if (preg_match('/^env\((?:\w++:)*+\w++\)$/', $match[1])) {
164164
throw new RuntimeException(sprintf('Using "%%%s%%" is not allowed in routing configuration.', $match[1]));
165165
}
166166

@@ -173,7 +173,7 @@ private function resolve($value)
173173
if (\is_string($resolved) || is_numeric($resolved)) {
174174
$this->collectedParameters[$match[1]] = $resolved;
175175

176-
return (string) $resolved;
176+
return (string) $this->resolve($resolved);
177177
}
178178

179179
throw new RuntimeException(sprintf('The container parameter "%s", used in the route configuration value "%s", must be a string or numeric, but it is of type %s.', $match[1], $value, \gettype($resolved)));

Tests/Routing/RouterTest.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Bundle\FrameworkBundle\Routing\Router;
1717
use Symfony\Component\Config\Loader\LoaderInterface;
1818
use Symfony\Component\DependencyInjection\Config\ContainerParametersResource;
19+
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
1920
use Symfony\Component\Routing\Route;
2021
use Symfony\Component\Routing\RouteCollection;
2122

@@ -278,13 +279,13 @@ public function testPatternPlaceholdersWithSfContainer()
278279
$routes->add('foo', new Route('/before/%parameter.foo%/after/%%escaped%%'));
279280

280281
$sc = $this->getServiceContainer($routes);
281-
$sc->setParameter('parameter.foo', 'foo');
282+
$sc->setParameter('parameter.foo', 'foo-%%escaped%%');
282283

283284
$router = new Router($sc, 'foo');
284285
$route = $router->getRouteCollection()->get('foo');
285286

286287
$this->assertEquals(
287-
'/before/foo/after/%escaped%',
288+
'/before/foo-%escaped%/after/%escaped%',
288289
$route->getPath()
289290
);
290291
}
@@ -313,6 +314,22 @@ public function testEnvPlaceholdersWithSfContainer()
313314
$router->getRouteCollection();
314315
}
315316

317+
public function testIndirectEnvPlaceholders()
318+
{
319+
$routes = new RouteCollection();
320+
321+
$routes->add('foo', new Route('/%foo%'));
322+
323+
$router = new Router($container = $this->getServiceContainer($routes), 'foo');
324+
$container->setParameter('foo', 'foo-%bar%');
325+
$container->setParameter('bar', '%env(string:FOO)%');
326+
327+
$this->expectException(RuntimeException::class);
328+
$this->expectExceptionMessage('Using "%env(string:FOO)%" is not allowed in routing configuration.');
329+
330+
$router->getRouteCollection();
331+
}
332+
316333
public function testHostPlaceholders()
317334
{
318335
$routes = new RouteCollection();

0 commit comments

Comments
 (0)