Fix Get-Culture -ListAvailable:$false and Get-Location -Stack:$false#27034
Open
SufficientDaikon wants to merge 1 commit intoPowerShell:masterfrom
Open
Fix Get-Culture -ListAvailable:$false and Get-Location -Stack:$false#27034SufficientDaikon wants to merge 1 commit intoPowerShell:masterfrom
SufficientDaikon wants to merge 1 commit intoPowerShell:masterfrom
Conversation
20 tasks
When -ListAvailable:$false or -Stack:$false is passed, the parameter binder selects the switch's ParameterSetName but the cmdlet code branches on the set name without checking the actual switch value. This causes Get-Culture to dump all ~800 cultures and Get-Location to show the stack instead of the current directory. Wrap the switch-path code in if (SwitchParam) with an else fallback to default behavior. Same pattern as 9 previously merged sibling PRs. Part of PowerShell#25242 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
6e8edd9 to
792e615
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Summary
Fixes
Get-Culture -ListAvailable:$falseandGet-Location -Stack:$false, which incorrectly execute the switch-true code path when the switch value is explicitly$false.Note
This follows the same fix pattern used in 9 previously merged sibling PRs. Part of the ongoing cleanup tracked in #25242.
The Bug
When
-ListAvailable:$falseor-Stack:$falseis passed, PowerShell's parameter binder selects the correspondingParameterSetName, but the cmdlet code branches on the set name without checking the actual switch value.Get-Culture -ListAvailable:$falseGet-Location -Stack:$falseflowchart TD A["-ListAvailable:$false"] --> B["Binder selects\nListAvailableParameterSet"] B --> C{"Branches on\nset name only"} C -->|"Before · bug"| D["Dumps all 800 cultures ❌"] C -->|"After · fix"| E{"if ListAvailable"} E -->|true| F["List all cultures"] E -->|false| G["Return current culture ✓"]The Fix
Wrap the switch-path code in
if (SwitchParam)with anelsefallback to default behavior:What Changed
GetCultureCommand.csListAvailableParameterSetwithif (ListAvailable), else return current cultureNavigation.csStackParameterSetwithif (Stack), else return current locationGet-Culture.Tests.ps1-ListAvailable:$falseregression testGet-Location.Tests.ps1-Stack:$falseregression testTests
-Stack:$false)9 sibling PRs already merged (same pattern)
-Empty:$false-Since:$false-Shuffle:$false-Shuffle:$false-ListAvailable:$false-UseWindowsPowerShell:$false-Qualifier/-NoQualifier/-Leaf/-IsAbsolute:$false-Repeat/-MtuSize/-Traceroute:$false-[Operator]:$falsePR Context
This is part of the ongoing
-Switch:$falsecleanup tracked in #25242. Nine sibling PRs using the identical fix pattern have already been reviewed and merged. Also open: #26551 coveringConvertTo-Csv/Export-Csv.PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header