Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reverse route for '' is not false #8024

Merged
merged 3 commits into from
Oct 13, 2023
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 === '') {
MGatner marked this conversation as resolved.
Show resolved Hide 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
Loading