-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Quoted command-line argument with space treats trailing backslash as escaping quote #21854
Comments
FWIW, shell commands and batch files process such arguments properly: > echo "C:\Program Files\"
"C:\Program Files\"
echo %1 > test.bat "C:\Program Files\"
> echo "C:\Program Files\"
"C:\Program Files\" |
/cc @nodejs/platform-windows @vsemozhetbyt can you confirm that this happens on master? |
Cannot reproduce on MacOS. ➜ out/Release/node ~/Code/temp/node/cli.js "/dev/null"
[ '/Users/ryzokuken/Code/nodejs/node/out/Release/node',
'/Users/ryzokuken/Code/temp/node/cli.js',
'/dev/null' ] |
Yes, this happens with |
Not a Node.js issue. This is how PowerShell and cmd parse arguments. Same behavior in Python. |
The logic of actually setting the value is fairly trivial and fool-proof: // process.argv
Local<Array> arguments = Array::New(env->isolate(), argc);
for (int i = 0; i < argc; ++i) {
arguments->Set(i, String::NewFromUtf8(env->isolate(), argv[i]));
}
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "argv"), arguments); Perhaps there's something wrong with the |
@seishun thanks for the clarification. |
Refs: https://ss64.com/nt/syntax-esc.html
|
@seishun If this is a PowerShell bug, why does this work correctly?
|
|
The similar issue with > cat test.txt
"C:\Program Files\"
> FINDSTR "C:\Program Files\\" test.txt
"C:\Program Files\"
> FINDSTR "C:\Program Files\" test.txt The last commannd just waits for inputs (processing all the parameters as a one string?) |
I have confirmed that @seishun is correct - this is a bug in PowerShell. foo.c:
Compiled with Microsoft C/C++ compiler v19.14.26433 for x86 to foo.exe
I apologize for the erroneous bug report. |
Opened issue with PowerShell: PowerShell/PowerShell#7400 |
I'm having this issue without PowerShell. I'm running the node process by WinAPI CreateProcess function with a command line like Node v14.17.3 |
As a kind of proof that this is not a Windows bug: running this command in the |
This also clearly states that the issue is with some programs that interpret the command line wrongly, not with a shell or the command line itself. This means, that nodejs just adopted the common bug that existed in some other programs that use the same RTL. Is the RTL bug a good excuse to not fix it in node? |
console.log(process.argv);
The above will show the issue in a console application run from PowerShell.
If:
then the backslash will escape the final quote, which will be included in the argument value.
Example:
node foo "C:\Program Files\"
Note that the final argument ends with a double-quote instead of a backslash.
The text was updated successfully, but these errors were encountered: