New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The specification of the call syntax of the native PowerShell command line prompt is not consistent. #15893
Comments
Is this a PowerShell issue or a Windows one? I don't know of any way to invoke a process on WIndows while bypassing the typical command line syntax. 🤷 Also, looking at the other issues you filed, the problem you're seeing looks just about the same between all of them, with only slight differences in how it presents, so I'm not sure what you're hoping to achieve other than confusing folks by filing them all separately. 😕 |
The main confusion of the input and result are:
Because the backslash is not defined by the PowerShell syntax specification as escape character, see escaped-character. But the backtick only. I don't know how the internal call structure is. So I cannot say where the internal issue for the call is. The only thing I know here is that the backslash is defined by DOS/cmd.exe as an in-quote escape character. Because the caret does not work within double quotes.
Thus I assume that a DOS based evaluation and execution is proceeded. I tried some calls for example with DOS based escaping, but failed due to the required biased quotes of the PowerShell, thus was not able to pass all my trial strings through to the DOS based call. Therefore I had to add even in the above call an extra double quote.
Therefore I did not managed to pass e.g. the following string due to the non-balanced double qoute error of the PowerShell:
The alternative:
passed, but did not work as expected. This is why I assume that a simple update of the specification will eventually not suffice for all scenarios. |
PS > pwsh -f .\1.ps1 '^"""a'
['^"a']
PS > gc .\1.ps1
"['$args']" |
There are multiple levels you need to take into account that aren't specifically PowerShell related.
Using my example above say you were to do the following in PowerShell (on Windows at least) $nativeArgs = @('argument1', "argument 2")
$bar = "value 123"
my.exe $nativeArgs foo "bar $bar" '{"foo": "$bar"}' What happens is the following:
Ultimately there is no one size fits all and it's made complex by the many different layers that are involved
|
@237dmitry
to the native layer with the expected literal result - from the native layer:
Which may have a different call context than the call of a native PowerShell script - see also @jborean93. Anyhow, this was just a simple trial to understand the instances of the call chain. |
@jborean93 My focus on the syntax specification in external code like Python is matched in particular by:
This is what I am scanning/lexing/tokenizing online and offline - argv and/or any complete or partial command line string. Therefore I require in particular the complete normative information about quoting and escaping. Spoken in terms of this issue - the missing parts of the syntax specification:
|
@vexx32
The tasks themself are a bit confusing, therefore I separated them in order to clearly distinguish and define the concrete issues case by case. |
This issue has been treated pretty extensively in #1995. There's also discussion in #13068. Essentially, from #1995 (comment), the Windows process creation API requires the command line as a single string rather than an array, and then parses that with Given the extensive discussion of this in pre-existing issues, I'll mark this and the other issues as duplicates of #1995. |
This issue has been marked as duplicate and has not had any activity for 1 day. It has been closed for housekeeping purposes. |
Prerequisites
Steps to reproduce
This issue is technically related to #15888, #15889, and #15892.
The specifications and definitions are:
The pure evaluation from the PowerShell prompt behaves as stated in about_Quoting_Rules and uses the syntax of the domain PowerShell-7.1 - B. Grammar
The call of a PowerShell script behaves the same way.
The call of an executable such as another PowerShell instance leaves the PowerShell syntax domain and passes the DOS/cmd.exe syntax domain before entering the PowerShell syntax domain again.
This is for example the case for:
where the DOS in-string escape character backslash is successfully applied.
The backslash is not specified in the grammar PowerShell-7.1 - B. Grammar by escaped-character.
Same with Python:
The latter leads me to the assumption, that the initial execution is actually performed in a DOS/cmd.exe like environment, thus escaped and quoted in accordance to the DOS/cmd.exe command line syntax rules. But I called a PowerShell executable at a PowerShell prompt. So I do not expect an intermediary DOS exec call with it's native command line syntax, which has significant differences. Some cases could even not be realized due to the partially contrary/non-compatible specifications.
This makes it difficult to scan/parse a raw call string statically. Because in each case the actuall call chain has to be determined.
The command line call syntax should not change during the call process. At least it should be protected and/or transformed appropriately and passed transparently to the target executable.
The user should have to apply one command line syntax only - PowerShell.
The number of the evaluations of the input command line should be determined and fixed - at best 1x for each call-level.
Expected behavior
Actual behavior
Error details
No response
Environment data
Visuals
No response
The text was updated successfully, but these errors were encountered: