Skip to content

fix: normalize directory separators in route file paths for Windows#10210

Open
jalexiscv wants to merge 1 commit into
codeigniter4:developfrom
jalexiscv:fix/bug-7474-windows-tests
Open

fix: normalize directory separators in route file paths for Windows#10210
jalexiscv wants to merge 1 commit into
codeigniter4:developfrom
jalexiscv:fix/bug-7474-windows-tests

Conversation

@jalexiscv
Copy link
Copy Markdown

Description

Fixes #7474 - [4.4] Failed tests on Windows

Problem

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 in loadRoutes() to fail, preventing route files from being recognized as already loaded.

This led to tests like testRun404Override failing because the 404 override routes from test support files weren't properly recognized.

Solution

Normalize all realpath() results in RouteCollection to use forward slashes by replacing \ with /. Applied in two locations:

  1. loadRoutes() - when normalizing the routeFiles array
  2. loadRoutes() - when normalizing the passed routesFile parameter

This makes path comparisons consistent across Windows and Unix platforms.

Changes

One file: system/Router/RouteCollection.php

  • loadRoutes(): normalize realpath() results with str_replace('\\', '/', ...)

Ref: #7474
Closes #7474

Fixes codeigniter4#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: codeigniter4#7474
@mergeable
Copy link
Copy Markdown

mergeable Bot commented May 18, 2026

Hi there, jalexiscv! 👋

Thank you for sending this PR!

We expect the following in all Pull Requests (PRs).

Important

We expect all code changes or bug-fixes to be accompanied by one or more tests added to our test suite to prove the code works.

If pull requests do not comply with the above, they will likely be closed. Since we are a team of volunteers, we don't have any more time to work
on the framework than you do. Please make it as painless for your contributions to be included as possible.

See https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/pull_request.md

Sincerely, the mergeable bot 🤖

Copy link
Copy Markdown
Contributor

@neznaika0 neznaika0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To support Windows, you need a comprehensive solution, starting with initialization index.php . Then all paths can be processed with a single normalize_path() function. For tests, you can temporarily replace slashes during assertion.

Copy link
Copy Markdown
Member

@paulbalandan paulbalandan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an incomplete fix. As I remember, I have proposed a similar normalize_path() helper function in the past. You can read on that for the history. In order to fix the issue, we would need:

  1. A centralised function to do the normalization (e.g. normalize_path())
  2. Adapt our testing workflows to run on windows (runs-on: windows-latest)
  3. A documentation write up

@paulbalandan paulbalandan added refactor Pull requests that refactor code tests needed Pull requests that need tests needs rework Changes requested by reviewer that are still pending docs needed Pull requests needing documentation write-ups and/or revisions. labels May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs needed Pull requests needing documentation write-ups and/or revisions. needs rework Changes requested by reviewer that are still pending refactor Pull requests that refactor code tests needed Pull requests that need tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: [4.4] Failed tests on Windows.

3 participants