Prefer literal Select-Object property matches by KirtiRamchandani · Pull Request #27515 · PowerShell/PowerShell
PR Summary
Makes Select-Object prefer an exact property-name match before treating wildcard-looking property arguments as wildcard patterns.
PR Context
Fix #25982.
The cmdlet currently treats property names containing wildcard characters only as wildcard patterns, even when the input object has a property whose literal name matches the requested value. This means a generated object with a property such as Foo[] cannot reliably select or expand that property even when the caller uses [WildcardPattern]::Escape().
This change checks for a literal property match first, using the wildcard-unescaped property expression where applicable. If no exact property exists, existing wildcard expansion behavior is preserved.
Regression tests cover:
- escaped literal property names such as
Foo[] - exact property names such as
Foo*taking precedence over wildcard expansion -ExpandPropertywith escaped literal property names
PR Checklist
- PR has a meaningful title
- Summarized changes
- This PR is focused on one issue
- Make sure all
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header - This PR is ready to merge and is not work-in-progress
- Breaking change: No
- User-facing change: Not required
- Tests added/updated
Validation
Start-PSBuild -NoPSModuleRestore -CI -SkipExperimentalFeatureGeneration -UseNuGetOrg- Direct repro with
[WildcardPattern]::Escape('Foo[]')succeeds for both-Propertyand-ExpandProperty. Start-PSPester -Path test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 -UseNuGetOrg -ThrowOnFailure -Terse -SkipTestToolBuild
Result: Select-Object.Tests.ps1 passed: 54 passed, 0 failed.