diff --git a/src/Symfony/Routing/Router.php b/src/Symfony/Routing/Router.php index 716fb8e79a9..5c14e4b7957 100644 --- a/src/Symfony/Routing/Router.php +++ b/src/Symfony/Routing/Router.php @@ -77,6 +77,7 @@ public function match(string $pathInfo): array $context->setPathInfo($pathInfo); $context->setScheme($baseContext->getScheme()); $context->setHost($baseContext->getHost()); + $context->setParameters($baseContext->getParameters()); try { $this->router->setContext($context); diff --git a/tests/Symfony/Routing/RouterTest.php b/tests/Symfony/Routing/RouterTest.php index 72cf66484e7..2126f3fb8d6 100644 --- a/tests/Symfony/Routing/RouterTest.php +++ b/tests/Symfony/Routing/RouterTest.php @@ -95,6 +95,22 @@ public function testMatch(): void $this->assertEquals(['bar'], $router->match('/app_dev.php/foo')); } + public function testMatchKeepsContextParameters(): void + { + $context = new RequestContext('', 'GET', 'localhost', 'https'); + $context->setParameter('_functions', 'functions'); + + $mockedRouter = $this->prophesize(RouterInterface::class); + $mockedRouter->getContext()->willReturn($context); + $mockedRouter->setContext(Argument::that(static fn (RequestContext $matchContext): bool => $matchContext !== $context && ['_functions' => 'functions'] === $matchContext->getParameters()))->shouldBeCalled(); + $mockedRouter->setContext($context)->shouldBeCalled(); + $mockedRouter->match('/foo')->willReturn(['bar']); + + $router = new Router($mockedRouter->reveal()); + + $this->assertEquals(['bar'], $router->match('/foo')); + } + public function testMatchDuplicatedBaseUrl(): void { $context = new RequestContext('/app', 'GET', 'localhost', 'https');