Skip to content

Commit 50bd285

Browse files
authored
Merge pull request #8024 from kenjis/fix-url-to-empty-string
fix: reverse route for `''` is not `false`
2 parents ce62326 + 61f080e commit 50bd285

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

system/Router/RouteCollection.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,10 @@ public function environment(string $env, Closure $callback): RouteCollectionInte
11561156
*/
11571157
public function reverseRoute(string $search, ...$params)
11581158
{
1159+
if ($search === '') {
1160+
return false;
1161+
}
1162+
11591163
// Named routes get higher priority.
11601164
foreach ($this->routesNames as $verb => $collection) {
11611165
if (array_key_exists($search, $collection)) {

tests/system/Helpers/URLHelper/MiscUrlTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ protected function setUp(): void
3838
parent::setUp();
3939

4040
Services::reset(true);
41+
Services::routes()->loadRoutes();
4142

4243
// Set a common base configuration (overriden by individual tests)
4344
$this->config = new App();

tests/system/Router/RouteCollectionReverseRouteTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ protected function getCollector(array $config = [], array $files = [], $moduleCo
5252
return (new RouteCollection($loader, $moduleConfig, new Routing()))->setHTTPVerb('get');
5353
}
5454

55+
public function testReverseRoutingEmptyString(): void
56+
{
57+
$routes = $this->getCollector();
58+
59+
$routes->add('/', 'Home::index');
60+
61+
$match = $routes->reverseRoute('');
62+
$this->assertFalse($match);
63+
}
64+
5565
public function testReverseRoutingFindsSimpleMatch(): void
5666
{
5767
$routes = $this->getCollector();

0 commit comments

Comments
 (0)