diff --git a/system/Router/Router.php b/system/Router/Router.php index 1b80377e26cf..04397d31d065 100644 --- a/system/Router/Router.php +++ b/system/Router/Router.php @@ -675,10 +675,7 @@ protected function setDefaultController() throw RouterException::forMissingDefaultRoute(); } - // Is the method being specified? - if (sscanf($this->controller, '%[^/]/%s', $class, $this->method) !== 2) { - $this->method = 'index'; - } + sscanf($this->controller, '%[^/]/%s', $class, $this->method); if (! is_file(APPPATH . 'Controllers/' . $this->directory . ucfirst($class) . '.php')) { return; diff --git a/tests/system/Router/RouterTest.php b/tests/system/Router/RouterTest.php index 3ba45ee03351..4ba9972b1288 100644 --- a/tests/system/Router/RouterTest.php +++ b/tests/system/Router/RouterTest.php @@ -199,6 +199,18 @@ public function testClosures() $this->assertSame($expects, '123-alpha'); } + public function testAutoRouteFindsDefaultControllerAndMethod() + { + $this->collection->setDefaultController('Test'); + $this->collection->setDefaultMethod('test'); + $router = new Router($this->collection, $this->request); + + $router->autoRoute('/'); + + $this->assertSame('Test', $router->controllerName()); + $this->assertSame('test', $router->methodName()); + } + public function testAutoRouteFindsControllerWithFileAndMethod() { $router = new Router($this->collection, $this->request);