Skip to content

Commit

Permalink
fix. uri have '/' method is ''
Browse files Browse the repository at this point in the history
  • Loading branch information
nyufeng committed May 12, 2020
1 parent a063f14 commit 7c8d3bf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion system/Router/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,11 @@ public function autoRoute(string $uri)
// has already been set.
if (! empty($segments))
{
$this->method = array_shift($segments);
$tempMethod = array_shift($segments);
if ($tempMethod !== '')
{
$this->method = $tempMethod;
}
}

if (! empty($segments))
Expand Down
11 changes: 11 additions & 0 deletions tests/system/Router/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -520,4 +520,15 @@ public function testAutoRouteMatchesZeroParams()
];
$this->assertEquals($expected, $router->params());
}

/**
* @see https://github.com/codeigniter4/CodeIgniter4/issues/2965
*/
public function testAutoRouteMethodEmpty()
{
$router = new Router($this->collection, $this->request);
$router->handle('Home/');
$this->assertEquals('Home', $router->controllerName());
$this->assertEquals('index', $router->methodName());
}
}

0 comments on commit 7c8d3bf

Please sign in to comment.