Skip to content

Support Split-Path switches with LiteralPath - #27517

Open
Kirtikumar Anandrao Ramchandani (KirtiRamchandani) wants to merge 3 commits into
PowerShell:masterfrom
KirtiRamchandani:fix/split-path-literal-switches
Open

Kirtikumar Anandrao Ramchandani (KirtiRamchandani) wants to merge 3 commits into
PowerShell:masterfrom
KirtiRamchandani:fix/split-path-literal-switches

Conversation

@KirtiRamchandani

Copy link
Copy Markdown
Contributor

PR Summary

Fixes #20705.

Split-Path -LiteralPath only had a single parameter set, so switches such as -Parent, -Leaf, -LeafBase, -Extension, -Qualifier, -NoQualifier, and -IsAbsolute could not be combined with it even though -LiteralPath should generally mirror -Path while suppressing wildcard expansion.

This adds separate literal-path parameter sets for the parsing switches so the valid combinations work, while conflicting switches remain rejected by parameter binding.

PR Context

The PowerShell cmdlets working group reviewed the issue and agreed that -LiteralPath should work with the same switches as -Path, excluding edge cases.

PR Checklist

  • Make sure all .cs, .ps1 and .psm1 files have the correct copyright header
  • Make sure you are merging your commits to the correct branch
  • Make sure you added tests for your changes
  • Make sure you run the relevant tests successfully

Validation

  • Start-PSBuild -NoPSModuleRestore -CI -SkipExperimentalFeatureGeneration -UseNuGetOrg
  • Start-PSPester -Path test/powershell/Modules/Microsoft.PowerShell.Management/Split-Path.Tests.ps1 -UseNuGetOrg -ThrowOnFailure -Terse -SkipTestToolBuild -BinDir

Result: Split-Path.Tests.ps1 passed: 17 passed, 0 failed.

Copilot AI review requested due to automatic review settings May 24, 2026 14:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds support for using Split-Path “parsing switches” with -LiteralPath, and introduces tests to validate correct parameter binding and conflicts.

Changes:

  • Extend SplitPathCommand with dedicated -LiteralPath parameter sets for -Leaf, -LeafBase, -Extension, -Qualifier, -NoQualifier, and -IsAbsolute
  • Add Pester coverage for Split-Path switch parsing behavior when -LiteralPath is used
  • Add a negative test for conflicting parsing switches with -LiteralPath

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
test/powershell/Modules/Microsoft.PowerShell.Management/Split-Path.Tests.ps1 Adds new tests ensuring parsing switches work (and conflict) with -LiteralPath.
src/Microsoft.PowerShell.Commands.Management/commands/management/ParsePathCommand.cs Adds new -LiteralPath-specific parameter sets so parsing switches bind correctly.

@KirtiRamchandani

Copy link
Copy Markdown
Contributor Author

Thanks for the review.

I'll update the test setup to use -LiteralPath for bracket-containing paths and compute expected values without wildcard interpretation on -Path. Also rewording the parameter-set summary for clarity.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the Review - Needed The PR is being reviewed label Sep 25, 2026
@microsoft-github-policy-service

Copy link
Copy Markdown
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.

Split-Path switches (-Leaf, -Parent, ...) do not work with -LiteralPath

2 participants