Skip to content

Commit f3b2f32

Browse files
committed
fix: routes keys must not be its names
1 parent 4142b50 commit f3b2f32

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

system/Router/RouteCollection.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1541,7 +1541,8 @@ protected function create(string $verb, string $from, $to, ?array $options = nul
15411541
// this works only because discovered routes are added just prior
15421542
// to attempting to route the request.
15431543
$routeKeyExists = isset($this->routes[$verb][$routeKey]);
1544-
if ((isset($this->routesNames[$verb][$routeKey]) || $routeKeyExists) && ! $overwrite) {
1544+
$routeNameExists = isset($this->routesNames[$verb][$routeKey]);
1545+
if (($routeNameExists || $routeKeyExists) && ! $overwrite) {
15451546
return;
15461547
}
15471548

tests/system/Router/RouteCollectionTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,17 @@ public function testNamedRouteAsPath(): void
11211121
$this->assertSame($expected, $routes->getRoutes());
11221122
}
11231123

1124+
public function testSameNamedRoutes(): void
1125+
{
1126+
service('request')->setMethod(Method::GET);
1127+
$routes = $this->getCollector();
1128+
1129+
$routes->get('from1', 'to1', ['as' => 'namedRoute']);
1130+
$routes->get('from2', 'to2', ['as' => 'namedRoute']);
1131+
1132+
$this->assertSame('/from1', $routes->reverseRoute('namedRoute'));
1133+
}
1134+
11241135
public function testAddRedirect(): void
11251136
{
11261137
$routes = $this->getCollector();

0 commit comments

Comments
 (0)