-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Closed
Labels
Issue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime
Description
Note: This is ultimately another manifestation of #5579.
-f, when passed an array that is invisibly [psobject]-wrapped, fails to recognize the array as such.
This can happen with arrays returned as a whole from cmdlets, such as with Write-Output -NoEnumerate and Get-Content -ReadCount.
Simplest, but contrived repro: '{0} {1}' -f ([psobject] (1, 2))
Note:
- When using an untyped function/script parameter,
[psobject]wrapping does not occur with arrays; it does, however, occur with scalar barewords that can be parsed as numbers, and then causes a similar problem: A "hybrid" bareword command argument that is parsed as a number unexpectedly behaves like a string with -f (format operator) #17199
Steps to reproduce
# Create two 2-element arrays: one with an expression, another via a cmdlet.
$arr1 = 1, 2
$arr2 = Write-Output -NoEnumerate 1, 2
'{0} {1}' -f $arr1 | Should -Be '1 2'
'{0} {1}' -f $arr2 | Should -Be '1 2'Expected behavior
Both tests should succeed.
Actual behavior
The 2nd test fails, because $arr2 is (invisibly) [psobject]-wrapped.
InvalidOperation: Error formatting a string: Index (zero based) must be greater than or equal to zero and less than the size of the argument list..
Environment data
PowerShell Core 7.2.0-preview.1
iSazonov
Metadata
Metadata
Assignees
Labels
Issue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime