Here is my sub-expression:
"""$((($l -split " """)[1] -split """ ")[0])"""
I have checked and found no unpaired parentheses. However powershell insists in saying "Missing closing ')' in expression." Interestingly, the expression
$((($l -split " """)[1] -split """ ")[0])
works fine.
Has anyone had similiar experience before? Is it a bug of Powershell?
This.. is really interesting, and yes I would consider it a bug at least so far.
Here's a much simpler repro:
"$("`"")"
"$("""")"
It seems to be caused by using either form of double quote escaping (backtick or double double quote), inside a sub-expression, inside an expandable string.
It also appears that this is error comes right down to the parser itself:
$sb = @'
"$("`"")"
'@
$tokens = $null
$er = $null
$ast = [System.Management.Automation.Language.Parser]::ParseInput($sb, [ref]$tokens, [ref]$er)
$ast.EndBlock.Statements[0].PipelineElements[0].Expression.NestedExpressions
$tokens[0].NestedTokens
The nested tokens/expressions it finds just aren't correct.
I tested with Windows PowerShell 5.1 and PowerShell Core 6.0.0-rc.2 on WLS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With