Skip to content

Commit 5e4d1fe

Browse files
committed
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: #7474
1 parent 2a1c348 commit 5e4d1fe

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

system/Router/RouteCollection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ public function __construct(FileLocatorInterface $locator, Modules $moduleConfig
297297
// Normalize the path string in routeFiles array.
298298
foreach ($this->routeFiles as $routeKey => $routesFile) {
299299
$realpath = realpath($routesFile);
300-
$this->routeFiles[$routeKey] = ($realpath === false) ? $routesFile : $realpath;
300+
$this->routeFiles[$routeKey] = ($realpath === false) ? $routesFile : str_replace('\\', '/', $realpath);
301301
}
302302
}
303303

@@ -316,7 +316,7 @@ public function loadRoutes(string $routesFile = APPPATH . 'Config/Routes.php')
316316

317317
// Normalize the path string in routesFile
318318
$realpath = realpath($routesFile);
319-
$routesFile = ($realpath === false) ? $routesFile : $realpath;
319+
$routesFile = ($realpath === false) ? $routesFile : str_replace('\\', '/', $realpath);
320320

321321
// Include the passed in routesFile if it doesn't exist.
322322
// Only keeping that around for BC purposes for now.

0 commit comments

Comments
 (0)