Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Respect -Qualifier/-NoQualifier/-Leaf/-IsAbsolute:$false in Split-Path#26474

Merged
iSazonov merged 4 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
yotsuda:fix/split-path-switchesyotsuda/PowerShell:fix/split-path-switchesCopy head branch name to clipboard
Nov 21, 2025
Merged

Respect -Qualifier/-NoQualifier/-Leaf/-IsAbsolute:$false in Split-Path#26474
iSazonov merged 4 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
yotsuda:fix/split-path-switchesyotsuda/PowerShell:fix/split-path-switchesCopy head branch name to clipboard

Conversation

@yotsuda

@yotsuda yotsuda commented Nov 18, 2025

Copy link
Copy Markdown
Contributor

PR Summary

This PR fixes the issue where -Qualifier:$false, -NoQualifier:$false, -Leaf:$false, and -IsAbsolute:$false are not respected in Split-Path, causing them to behave the same as their $true counterparts.

Fixes #26470
Related to #25242

PR Context

When these switch parameters are explicitly set to $false for Split-Path, the cmdlet incorrectly behaves as if they were set to $true. This occurs because the code uses ParameterSetName (a string) in a switch statement instead of checking the actual boolean values of the switch parameters.

This fix converts the switch statement to an if-else chain that directly checks each switch parameter's boolean value, ensuring that explicit $false values are properly respected.

Changes

  • Modified ParsePathCommand.cs: Converted the switch statement to an if-else chain that checks the actual boolean values of -IsAbsolute, -Qualifier, -Leaf/-LeafBase/-Extension, and -NoQualifier
  • Added 4 test cases in Split-Path.Tests.ps1 to verify each switch parameter respects :$false

Testing

  • Added new tests for explicit :$false parameter handling:
    • "Should handle explicit -Qualifier:`$false parameter value correctly"
    • "Should handle explicit -NoQualifier:`$false parameter value correctly"
    • "Should handle explicit -Leaf:`$false parameter value correctly"
    • "Should handle explicit -IsAbsolute:`$false parameter value correctly"
  • Each test verifies that when the switch parameter is set to $false, the cmdlet falls back to default behavior (returning the parent path)
  • Pre-fix: All 4 new tests fail
  • Post-fix: All 4 new tests pass
  • All 11 existing tests continue to pass

PR Checklist

@iSazonov iSazonov added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Nov 18, 2025
@iSazonov iSazonov requested a review from Copilot November 18, 2025 12:47

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

This PR fixes a bug where Split-Path cmdlet doesn't respect explicit :$false values for switch parameters -Qualifier, -NoQualifier, -Leaf, and -IsAbsolute. Previously, these switches behaved identically whether set to $true or $false due to the code checking parameter set names instead of actual boolean values.

  • Converted switch-case statement to if-else chain that checks actual boolean values of switch parameters
  • Added comprehensive test coverage for all four affected parameters with explicit :$false values

Reviewed Changes

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

File Description
src/Microsoft.PowerShell.Commands.Management/commands/management/ParsePathCommand.cs Refactored ProcessRecord method to check switch parameter boolean values instead of parameter set names, enabling proper handling of explicit :$false values
test/powershell/Modules/Microsoft.PowerShell.Management/Split-Path.Tests.ps1 Added 4 new test cases validating that -Qualifier:$false, -NoQualifier:$false, -Leaf:$false, and -IsAbsolute:$false correctly fall back to default parent path behavior; also fixed formatting spacing issue on existing test

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/powershell/Modules/Microsoft.PowerShell.Management/Split-Path.Tests.ps1 Outdated
Comment thread test/powershell/Modules/Microsoft.PowerShell.Management/Split-Path.Tests.ps1 Outdated
yotsuda and others added 2 commits November 19, 2025 07:28
…Path.Tests.ps1

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…Path.Tests.ps1

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@iSazonov iSazonov merged commit bb712de into PowerShell:master Nov 21, 2025
49 of 54 checks passed
@yotsuda yotsuda deleted the fix/split-path-switches branch November 21, 2025 22:59
@iSazonov iSazonov self-assigned this Nov 22, 2025
SIRMARGIN pushed a commit to SIRMARGIN/PowerShell that referenced this pull request Dec 12, 2025
kilasuit pushed a commit to kilasuit/PowerShell that referenced this pull request Jan 2, 2026
JustinGrote pushed a commit to JustinGrote/PowerShell that referenced this pull request Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

-Qualifier/-NoQualifier/-Leaf/-IsAbsolute:$false not respected in Split-Path

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.