-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Closed
Labels
Breaking-Changebreaking change that may affect usersbreaking change that may affect usersIssue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility module
Description
When I originally wrote up the proposal for -AsArray
in #6327, I meant it to work like @(...)
:
That is, the input should be converted to an array (and serialized as such) unless it already is one.
Instead, -AsArray
, as currently implemented, unconditionally treats the input as an array.
With pipeline input, which automatically gets enumerated, that usually makes no difference, but it does when you pass the inputs as an argument.
Steps to reproduce
ConvertTo-Json -AsArray 1 -Compress | Should -Be '[1]'
ConvertTo-Json -AsArray 1,2 -Compress | Should -Be '[1,2]'
ConvertTo-Json -AsArray @() -Compress | Should -Be '[]'
Expected behavior
All tests should pass.
Actual behavior
The last 2 tests fail, because they wrap the already array-valued input in an extra array:
Expected length: 5 Actual length: 7 Strings differ at index 1.
Expected: '[1,2]'
But was: '[[1,2]]'
Expected length: 5 Actual length: 7 Strings differ at index 1.
Expected: '[]'
But was: '[[]]'
Environment data
PowerShell Core 7.0.0-preview.5
vexx32
Metadata
Metadata
Assignees
Labels
Breaking-Changebreaking change that may affect usersbreaking change that may affect usersIssue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility module