Skip to content

ModuleCmdletBase: Use Path.Combine instead of + "\\" to append a ps1xml path#27038

Open
powercode wants to merge 1 commit intoPowerShell:masterfrom
powercode:GetListOfFilesFromData_fix
Open

ModuleCmdletBase: Use Path.Combine instead of + "\\" to append a ps1xml path#27038
powercode wants to merge 1 commit intoPowerShell:masterfrom
powercode:GetListOfFilesFromData_fix

Conversation

@powercode
Copy link
Collaborator

@powercode powercode commented Mar 16, 2026

PR Summary

There is an edge case when testing binary modules on Linux, where we get into the code path

if (string.Equals(psHome, dir, StringComparison.OrdinalIgnoreCase) ||
   (alternateDirToCheck != null && string.Equals(alternateDirToCheck, dir, StringComparison.OrdinalIgnoreCase)))
   {
        // The ps1xml file no longer exists in $PSHOME.  Downstream, we expect a resolved path,
        // which we can't really do b/c the file doesn't exist.
        fixedFileName = psHome + "\\" + s);
    }

The fix is

    fixedFileName = Path.Combine(psHome, s);

This causes the module load to fail because the engine tries to load types and formats from somepath/bin\Module.formats.ps1xml. Note the backslash.

PR Context

I've only seen this in unit tests hosting PowerShell, hosting powershell.

PR Checklist

@powercode powercode requested a review from a team as a code owner March 16, 2026 07:32
Copilot AI review requested due to automatic review settings March 16, 2026 07:32
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes an OS-specific path separator bug when synthesizing a “resolved” ps1xml path under $PSHOME (or an alternate PSHome-adjacent directory) during module manifest processing, which could otherwise yield Windows-style \ separators on non-Windows systems.

Changes:

  • Replace manual string concatenation (psHome + "\\" + ...) with Path.Combine(psHome, ...) when constructing the fallback ps1xml path.

You can also share your feedback on Copilot code review. Take the survey.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Review - Needed The PR is being reviewed label Mar 23, 2026
@microsoft-github-policy-service
Copy link
Contributor

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

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

Labels

Review - Needed The PR is being reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants