[Shell] Azure CLI receives corrupted arguments in PowerShell
Describe the bug
When invoking az in PowerShell, due to the known issue of PowerShell https://github.com/PowerShell/PowerShell/issues/1995, arguments passed to Azure CLI may get corrupted. For example, literal double quotes (") are lost:
# PowerShell
> az '{"signInAudience":"AzureADAndMicrosoftAccounts"}' --debug
Command arguments: ['{signInAudience:AzureADAndMicrosoftAccounts}', '--debug']
This contradicts the behavior of Bash:
# Bash
$ az '{"signInAudience":"AzureADAndMicrosoftAccounts"}' --debug
Command arguments: ['{"signInAudience":"AzureADAndMicrosoftAccounts"}', '--debug']
Impact
This is mainly affecting
- passing JSON as an argument as in
az rest --body {JSON}(#15512)# not working az rest ... --body '{"signInAudience":"AzureADandPersonalMicrosoftAccount"}' # working az rest ... --body '{\"signInAudience\":\"AzureADandPersonalMicrosoftAccount\"}' - using JMESPATH
--query(#13152)# not working az version --query '"azure-cli"' # working az version --query '\"azure-cli\"'
Workaround
Until this issue is fixed by PowerShell, arguments with special characters (", ,, &...) need to be escaped twice, one for CMD, one for PowerShell.
More info: Quoting issues with PowerShell
All similar issues are categorized under the Shell - PowerShell label. By now, received #7054, #8070, #8630, #8827, #9047, #9228, #9742, #10370, #10997, #11003, #1100, #11641, #11668, #12970, #13152, #13208, #13340, #13882, #15214, #15512.
The PowerShell issue seems to be fixed in PowerShell 7.3 : https://github.com/PowerShell/PowerShell/issues/1995#issuecomment-1211457683