Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions system/Router/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,10 @@ public function environment(string $env, Closure $callback): RouteCollectionInte
*/
public function reverseRoute(string $search, ...$params)
{
if ($search === '') {
Comment thread
MGatner marked this conversation as resolved.
return false;
}

// Named routes get higher priority.
foreach ($this->routesNames as $verb => $collection) {
if (array_key_exists($search, $collection)) {
Expand Down
1 change: 1 addition & 0 deletions tests/system/Helpers/URLHelper/MiscUrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ protected function setUp(): void
parent::setUp();

Services::reset(true);
Services::routes()->loadRoutes();

// Set a common base configuration (overriden by individual tests)
$this->config = new App();
Expand Down
10 changes: 10 additions & 0 deletions tests/system/Router/RouteCollectionReverseRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ protected function getCollector(array $config = [], array $files = [], $moduleCo
return (new RouteCollection($loader, $moduleConfig, new Routing()))->setHTTPVerb('get');
}

public function testReverseRoutingEmptyString(): void
{
$routes = $this->getCollector();

$routes->add('/', 'Home::index');

$match = $routes->reverseRoute('');
$this->assertFalse($match);
}

public function testReverseRoutingFindsSimpleMatch(): void
{
$routes = $this->getCollector();
Expand Down