diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index 82c6a6dd5bbe..36b8e4d52340 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -28,7 +28,9 @@ class RouteCollection implements RouteCollectionInterface { /** * The namespace to be added to any Controllers. - * Defaults to the global namespaces (\) + * Defaults to the global namespaces (\). + * + * This must have a trailing backslash (\). * * @var string */ @@ -288,7 +290,7 @@ public function __construct(FileLocator $locator, Modules $moduleConfig, Routing $this->httpHost = Services::request()->getServer('HTTP_HOST'); // Setup based on config file. Let routes file override. - $this->defaultNamespace = $routing->defaultNamespace; + $this->defaultNamespace = rtrim($routing->defaultNamespace, '\\') . '\\'; $this->defaultController = $routing->defaultController; $this->defaultMethod = $routing->defaultMethod; $this->translateURIDashes = $routing->translateURIDashes; diff --git a/tests/system/Test/FeatureTestTraitTest.php b/tests/system/Test/FeatureTestTraitTest.php index 0f5bb7ce33d5..aee912281c76 100644 --- a/tests/system/Test/FeatureTestTraitTest.php +++ b/tests/system/Test/FeatureTestTraitTest.php @@ -11,9 +11,11 @@ namespace CodeIgniter\Test; +use CodeIgniter\Config\Factories; use CodeIgniter\Events\Events; use CodeIgniter\Exceptions\PageNotFoundException; use CodeIgniter\HTTP\Response; +use Config\Routing; use Config\Services; /** @@ -616,4 +618,15 @@ public function testSetupRequestBodyWithBody(): void $this->assertSame('test', $request->getBody()); } + + public function testAutoRoutingLegacy() + { + $config = config(Routing::class); + $config->autoRoute = true; + Factories::injectMock('config', Routing::class, $config); + + $response = $this->get('home/index'); + + $response->assertOK(); + } }