{{ message }}
Fix Get-Culture -ListAvailable:$false and Get-Location -Stack:$false - #27034
Open
Ahmed Taha (SufficientDaikon) wants to merge 2 commits into
Open
Fix Get-Culture -ListAvailable:$false and Get-Location -Stack:$false#27034Ahmed Taha (SufficientDaikon) wants to merge 2 commits into
Ahmed Taha (SufficientDaikon) wants to merge 2 commits into
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>
Ahmed Taha (SufficientDaikon)
force-pushed
the
fix/switch-false-culture-location
branch
from
March 24, 2026 15:41
6e8edd9 to
792e615
Compare
This was referenced Mar 24, 2026
Contributor
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
Copilot started reviewing on behalf of
Ahmed Taha (SufficientDaikon)
July 22, 2026 14:23
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes incorrect cmdlet behavior when a switch parameter is explicitly passed as $false, ensuring -Switch:$false behaves the same as omitting the switch (consistent with the ongoing -Switch:$false cleanup tracked in #25242).
Changes:
- Update
Get-Cultureto only execute theListAvailablepath whenListAvailableis actually$true; otherwise return current culture. - Update
Get-Locationto only execute the stack path whenStackis actually$true; otherwise return current location. - Add Pester regression tests for
Get-Culture -ListAvailable:$falseandGet-Location -Stack:$false.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Culture.Tests.ps1 | Adds regression test for -ListAvailable:$false returning current culture. |
| test/powershell/Modules/Microsoft.PowerShell.Management/Get-Location.Tests.ps1 | Adds regression test for -Stack:$false returning current location (PathInfo). |
| src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetCultureCommand.cs | Guards ListAvailableParameterSet behavior with if (ListAvailable); otherwise falls back to current-culture behavior. |
| src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs | Guards StackParameterSet behavior with if (Stack); otherwise falls back to current-location behavior. |
Comment on lines
+104
to
110
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