Skip to content

Commit 1804bab

Browse files
authored
Merge pull request #7871 from kenjis/fix-auto-route-legacy
fix: auto route legacy does not work
2 parents 98239ad + 681f74d commit 1804bab

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

system/Router/RouteCollection.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ class RouteCollection implements RouteCollectionInterface
2828
{
2929
/**
3030
* The namespace to be added to any Controllers.
31-
* Defaults to the global namespaces (\)
31+
* Defaults to the global namespaces (\).
32+
*
33+
* This must have a trailing backslash (\).
3234
*
3335
* @var string
3436
*/
@@ -288,7 +290,7 @@ public function __construct(FileLocator $locator, Modules $moduleConfig, Routing
288290
$this->httpHost = Services::request()->getServer('HTTP_HOST');
289291

290292
// Setup based on config file. Let routes file override.
291-
$this->defaultNamespace = $routing->defaultNamespace;
293+
$this->defaultNamespace = rtrim($routing->defaultNamespace, '\\') . '\\';
292294
$this->defaultController = $routing->defaultController;
293295
$this->defaultMethod = $routing->defaultMethod;
294296
$this->translateURIDashes = $routing->translateURIDashes;

tests/system/Test/FeatureTestTraitTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111

1212
namespace CodeIgniter\Test;
1313

14+
use CodeIgniter\Config\Factories;
1415
use CodeIgniter\Events\Events;
1516
use CodeIgniter\Exceptions\PageNotFoundException;
1617
use CodeIgniter\HTTP\Response;
18+
use Config\Routing;
1719
use Config\Services;
1820

1921
/**
@@ -616,4 +618,15 @@ public function testSetupRequestBodyWithBody(): void
616618

617619
$this->assertSame('test', $request->getBody());
618620
}
621+
622+
public function testAutoRoutingLegacy()
623+
{
624+
$config = config(Routing::class);
625+
$config->autoRoute = true;
626+
Factories::injectMock('config', Routing::class, $config);
627+
628+
$response = $this->get('home/index');
629+
630+
$response->assertOK();
631+
}
619632
}

0 commit comments

Comments
 (0)