From 80f23a1e8b755e89636a91812feeb1d90e7eaca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Thu, 8 Jan 2026 23:06:53 +0100 Subject: [PATCH 1/2] fix: cast route name to string in preg_match calls Ensure route names are treated as strings in preg_match to handle numeric route names like '404' that PHP converts to integers in arrays, fixing compatibility with Symfony 6.2. --- Extractor/ExposedRoutesExtractor.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Extractor/ExposedRoutesExtractor.php b/Extractor/ExposedRoutesExtractor.php index 1c8e475..8764c3e 100644 --- a/Extractor/ExposedRoutesExtractor.php +++ b/Extractor/ExposedRoutesExtractor.php @@ -63,7 +63,7 @@ public function getRoutes(): RouteCollection continue; } - preg_match('#^'.$this->pattern.'$#', $name, $matches); + preg_match('#^'.$this->pattern.'$#', (string)$name, $matches); if (0 === count($matches)) { continue; @@ -172,10 +172,10 @@ public function getResources(): array /** * {@inheritDoc} */ - public function isRouteExposed(Route $route, $name): bool + public function isRouteExposed(Route $route, string $name): bool { if (false === $route->hasOption('expose')) { - return '' !== $this->pattern && preg_match('#^'.$this->pattern.'$#', $name); + return '' !== $this->pattern && preg_match('#^'.$this->pattern.'$#', (string)$name); } $status = $route->getOption('expose'); From 98a780c85026c27b359553b9875beaa8b3987820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Thu, 8 Jan 2026 23:10:58 +0100 Subject: [PATCH 2/2] test: add test for numeric route names Add testGetRoutesWithNumericNames to ensure routes with numeric names like '404' are properly handled and exposed, covering the fix for Symfony 6.2 compatibility. --- Extractor/ExposedRoutesExtractor.php | 4 ++-- Tests/Extractor/ExposedRoutesExtractorTest.php | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Extractor/ExposedRoutesExtractor.php b/Extractor/ExposedRoutesExtractor.php index 8764c3e..c151222 100644 --- a/Extractor/ExposedRoutesExtractor.php +++ b/Extractor/ExposedRoutesExtractor.php @@ -58,7 +58,7 @@ public function getRoutes(): RouteCollection $expose = $route->getOption('expose'); if (false !== $expose && 'false' !== $expose) { - $routes->add($name, $route); + $routes->add((string)$name, $route); } continue; } @@ -77,7 +77,7 @@ public function getRoutes(): RouteCollection $route = clone $route; $route->setOption('expose', $domain); - $routes->add($name, $route); + $routes->add((string)$name, $route); } return $routes; diff --git a/Tests/Extractor/ExposedRoutesExtractorTest.php b/Tests/Extractor/ExposedRoutesExtractorTest.php index e631b95..9331ac4 100644 --- a/Tests/Extractor/ExposedRoutesExtractorTest.php +++ b/Tests/Extractor/ExposedRoutesExtractorTest.php @@ -175,7 +175,25 @@ public function provideTestGetHostOverHttps(): array 'HTTPS Non-Standard' => ['127.0.0.1', 9876, '127.0.0.1:9876'], ]; } + public function testGetRoutesWithNumericNames(): void + { + $expected = new RouteCollection(); + $expected->add('404', new Route('/404')); + $expected->add('500', new Route('/500')); + $expected->add('literal', new Route('/literal')); + + $router = $this->getRouter($expected); + $extractor = new ExposedRoutesExtractor($router, ['.*'], $this->cacheDir, []); + $routes = $extractor->getRoutes(); + $this->assertCount(3, $routes); + + // Verify that numeric route names are handled correctly + $this->assertTrue($extractor->isRouteExposed($routes->get('404'), '404')); + $this->assertTrue($extractor->isRouteExposed($routes->get('500'), '500')); + // Test with integer key as well, since PHP may convert string keys to int + $this->assertTrue($extractor->isRouteExposed($routes->get('404'), '404')); + } /** * Get a mock object which represents a Router. */