fix(RouteParser): bail out if method name contains hashtag

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
pull/42678/head
Ferdinand Thiessen 2025-05-15 13:57:03 +07:00
parent 63ba61487b
commit e4ed062d68
No known key found for this signature in database
GPG Key ID: 45FAE7268762B400
2 changed files with 10 additions and 1 deletions

@ -76,7 +76,7 @@ class RouteParser {
$url = $root . '/' . ltrim($route['url'], '/');
$verb = strtoupper($route['verb'] ?? 'GET');
$split = explode('#', $name, 2);
$split = explode('#', $name, 3);
if (count($split) !== 2) {
throw new \UnexpectedValueException('Invalid route name: use the format foo#bar to reference FooController::bar');
}

@ -142,6 +142,15 @@ class RouteParserTest extends \Test\TestCase {
$this->parser->parseDefaultRoutes($routes, 'app1');
}
public function testParseRoutesInvalidName2(): void {
$routes = ['routes' => [
['name' => 'folders#open#action', 'url' => '/{folderId}/open', 'verb' => 'GET']
]];
$this->expectException(\UnexpectedValueException::class);
$this->parser->parseDefaultRoutes($routes, 'app1');
}
public function testParseRoutesEmpty(): void {
$routes = ['routes' => []];