Skip to content

Support Split-Path switches with LiteralPath#27517

Open
KirtiRamchandani wants to merge 3 commits into
PowerShell:masterfrom
KirtiRamchandani:fix/split-path-literal-switches
Open

Support Split-Path switches with LiteralPath#27517
KirtiRamchandani wants to merge 3 commits into
PowerShell:masterfrom
KirtiRamchandani:fix/split-path-literal-switches

Conversation

@KirtiRamchandani
Copy link
Copy Markdown

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
@KirtiRamchandani KirtiRamchandani requested a review from a team as a code owner May 24, 2026 14:28
Copy link
Copy Markdown
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

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.

Comment on lines +102 to +103
$null = New-Item -ItemType Directory -Path $literalDir
$null = New-Item -ItemType File -Path $literalPath
Comment on lines +109 to +110
Split-Path -LiteralPath $literalPath -Qualifier | Should -BeExactly (Split-Path -Path $literalPath -Qualifier)
Split-Path -LiteralPath $literalPath -NoQualifier | Should -BeExactly (Split-Path -Path $literalPath -NoQualifier)
Comment on lines +97 to +100
/// <summary>
/// The parameter set name to get the noqualifier set for LiteralPath.
/// </summary>
private const string literalPathNoQualifierSet = "LiteralPathNoQualifierSet";
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.

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

2 participants