Skip to content

Filesystem API: Recognize Windows drive paths with forward slashes as absolute - #16180

Open
irozum wants to merge 1 commit into
WordPress:trunkfrom
irozum:fix/48289-path-is-absolute-windows-forward-slash
Open

irozum wants to merge 1 commit into
WordPress:trunkfrom
irozum:fix/48289-path-is-absolute-windows-forward-slash

Conversation

@irozum

@irozum irozum commented Nov 23, 2026

Copy link
Copy Markdown

The problem:

  • path_is_absolute() only treats a Windows drive-letter path as absolute when a backslash follows the drive letter (C:\foo). A path with a forward slash (C:/foo) falls through and is reported as relative.
  • wp_normalize_path() converts every backslash to a forward slash, so on Windows any normalized absolute path (for example C:/wamp/www/wp-content) is wrongly reported as relative. Windows itself accepts / as a separator, so C:/foo is a valid absolute path.
  • The only core caller, path_join(), then joins such a path onto the base instead of returning it unchanged, producing <base>/C:/foo.

The fix:

  • The drive-letter check in path_is_absolute() now accepts either separator after X: (#^[a-zA-Z]:[\\\\/]#).
  • Drive-relative paths such as C:foo and a bare C: still aren't absolute, since a separator is still required.
  • The docblock example and a @since 7.2.0 changelog entry are updated. wp_normalize_path() is unchanged. The earlier patches on the ticket used DIRECTORY_SEPARATOR, which the ticket discussion showed doesn't help, because the separator comes from normalization rather than the host OS.

Tests:

  • test_path_is_absolute_accepts_windows_drive_path_with_forward_slashes() covers C:/, C:/WINDOWS, c:/foo/bar, D:/wamp/www/wp-content, and the exact case from the ticket, wp_normalize_path( 'C:\\wamp\\www\\wp-content' ). All five fail on trunk and pass with the fix.
  • test_path_is_absolute_rejects_windows_drive_relative_path() guards against widening the check too far: C:foo and C: stay relative.
  • The full Tests_Functions class passes, and PHPCS and PHPStan report nothing new compared with trunk.

Credits: this builds on the report and investigation by @paultgoodchild, with discussion from @jrf, @itowhid06 and @apedog, and the request for unit tests from @audrasjb.

Trac ticket: https://core.trac.wordpress.org/ticket/48289

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5 (planning and verification), Claude Sonnet 5.5 (implementation)
Used for: Implementation, tests, and PR description.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @jrf.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

Core Committers: Use this line as a base for the props when committing in SVN:

Props irozum.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@jrf

jrf commented Nov 23, 2026

Copy link
Copy Markdown

Just FYI — I am not the jrf that you continue to reference in your PRs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants