From 5e4d1fe2c2cb82eb10cc20b082a48fc074e55306 Mon Sep 17 00:00:00 2001 From: jalexiscv Date: Sun, 17 May 2026 22:39:25 -0500 Subject: [PATCH] fix: normalize directory separators in route file paths for Windows Fixes #7474 On Windows, realpath() returns paths with backslashes (e.g., D:\path\to\file.php) while routeFiles paths use forward slashes (App/Config/Routes.php). This caused in_array() comparison to fail in loadRoutes(), preventing route files from being recognized as already loaded and causing 404 override tests to fail. The fix normalizes all realpath() results to use forward slashes, making path comparisons consistent across platforms. Ref: https://github.com/codeigniter4/CodeIgniter4/issues/7474 --- system/Router/RouteCollection.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index 3c08958604d2..d01202309a69 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -297,7 +297,7 @@ public function __construct(FileLocatorInterface $locator, Modules $moduleConfig // Normalize the path string in routeFiles array. foreach ($this->routeFiles as $routeKey => $routesFile) { $realpath = realpath($routesFile); - $this->routeFiles[$routeKey] = ($realpath === false) ? $routesFile : $realpath; + $this->routeFiles[$routeKey] = ($realpath === false) ? $routesFile : str_replace('\\', '/', $realpath); } } @@ -316,7 +316,7 @@ public function loadRoutes(string $routesFile = APPPATH . 'Config/Routes.php') // Normalize the path string in routesFile $realpath = realpath($routesFile); - $routesFile = ($realpath === false) ? $routesFile : $realpath; + $routesFile = ($realpath === false) ? $routesFile : str_replace('\\', '/', $realpath); // Include the passed in routesFile if it doesn't exist. // Only keeping that around for BC purposes for now.