Skip to content

Fix Windows path separator incompatibility in handle_imports#10

Draft
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-handle-imports-windows
Draft

Fix Windows path separator incompatibility in handle_imports#10
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-handle-imports-windows

Conversation

Copy link

Copilot AI commented Feb 11, 2026

On Windows/IIS, realpath() returns paths with backslashes while the constructed $filename uses forward slashes, causing the security check to always fail and block all imports.

Changes

  • Normalize both paths using wp_normalize_path() before comparison
  • Store realpath() result to avoid duplicate calls and enable explicit false-check for non-existent files
// Before
if ( $filename !== realpath( $filename ) ) {
    continue;
}

// After
$realpath = realpath( $filename );
if ( ! $realpath || wp_normalize_path( $filename ) !== wp_normalize_path( $realpath ) ) {
    continue;
}

The security check (directory traversal prevention) remains intact since realpath() resolves the canonical path before normalization.

Original prompt

This section details on the original issue you should resolve

<issue_title>on Windows/IIS the function handle_imports not work correctly due to the path separator.</issue_title>
<issue_description>the function handle_imports in the file class.add-from-server.php not work correctly on windows,the code below:

if ( $filename !== realpath( $filename ) ) {
continue;
}

on Windows/IIS,the path separator are '\', '$filename !== realpath( $filename )' always is true.
</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits February 11, 2026 02:52
Co-authored-by: dd32 <767313+dd32@users.noreply.github.com>
Co-authored-by: dd32 <767313+dd32@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix handle_imports function for Windows path separator issue Fix Windows path separator incompatibility in handle_imports Feb 11, 2026
Copilot AI requested a review from dd32 February 11, 2026 02:55
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.

on Windows/IIS the function handle_imports not work correctly due to the path separator.

2 participants