Skip to content

Commit fc8b23a

Browse files
authored
fix(symfony): keep the router context parameters when matching an IRI (#8859)
fixes #8850 Co-authored-by: Alejandro Borrego <210245044+abp002@users.noreply.github.com>
1 parent 75e4769 commit fc8b23a

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

‎src/Symfony/Routing/Router.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public function match(string $pathInfo): array
7777
$context->setPathInfo($pathInfo);
7878
$context->setScheme($baseContext->getScheme());
7979
$context->setHost($baseContext->getHost());
80+
$context->setParameters($baseContext->getParameters());
8081

8182
try {
8283
$this->router->setContext($context);

‎tests/Symfony/Routing/RouterTest.php‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,22 @@ public function testMatch(): void
9595
$this->assertEquals(['bar'], $router->match('/app_dev.php/foo'));
9696
}
9797

98+
public function testMatchKeepsContextParameters(): void
99+
{
100+
$context = new RequestContext('', 'GET', 'localhost', 'https');
101+
$context->setParameter('_functions', 'functions');
102+
103+
$mockedRouter = $this->prophesize(RouterInterface::class);
104+
$mockedRouter->getContext()->willReturn($context);
105+
$mockedRouter->setContext(Argument::that(static fn (RequestContext $matchContext): bool => $matchContext !== $context && ['_functions' => 'functions'] === $matchContext->getParameters()))->shouldBeCalled();
106+
$mockedRouter->setContext($context)->shouldBeCalled();
107+
$mockedRouter->match('/foo')->willReturn(['bar']);
108+
109+
$router = new Router($mockedRouter->reveal());
110+
111+
$this->assertEquals(['bar'], $router->match('/foo'));
112+
}
113+
98114
public function testMatchDuplicatedBaseUrl(): void
99115
{
100116
$context = new RequestContext('/app', 'GET', 'localhost', 'https');

0 commit comments

Comments
 (0)