The issue lies whenever that user input includes any thing escapable such as double quotes.
Let's say a user tries to run the next:
echo "Hello World"
After looking through proc explorer and exploring the source I've noticed that what's being passed to the command line looks as follow:
echo \"Hello World\"
As you can see there is the unnecessary escape of the double quotes, what's more interesting that through debugging the library's code I've found out that it escapes more than that, through this exact process:
echo "Hello World"
echo \"Hello World\"
echo \\\"Hello World\\\"
Now ... for this specific command it ain't that bad of an issue but where it comes to more sophisticated commands such as:
the issue arises in the parameter of the /TN flag, trying to run this specific command through:
let input = r#"SCHTASKS /Create /TN "New Task" /SC HOURLY /TR blah.exe /RL HIGHEST"#
#[cfg(target_os = "windows")]
let output = run_fun! (
cmd /c $input
);
We get an error back because the quotes were escaped, instead of successfully creating the task/running the command at all, what we're getting back is an error:
ERROR: Invalid argument/option - 'Task"'.
Type "SCHTASKS /CREATE /?" for usage.
this happens because the command cmd_lib actually runs looks like:
SCHTASKS /Create /TN \"New Task\" /SC HOURLY /TR blah.exe /RL HIGHEST <- Notice the escaped double quotes
Is there anything we can do about it? I've tried to hack into the internals of the library with little to no success in that matter.
any help will be appreciated.
$input will always be treated as one single argument, you need to use vector $[input] if you want to have a list of arguments. See readme and related bug #42.
OS: Windows (don't know if it's an issue on Linux)
Let's say my application accepts arbitrary commands dynamically via user input I have the next:
The issue lies whenever that user input includes any thing escapable such as double quotes. Let's say a user tries to run the next:
After looking through proc explorer and exploring the source I've noticed that what's being passed to the command line looks as follow:
As you can see there is the unnecessary escape of the double quotes, what's more interesting that through debugging the library's code I've found out that it escapes more than that, through this exact process:
echo "Hello World"
echo \"Hello World\"
echo \\\"Hello World\\\"
Now ... for this specific command it ain't that bad of an issue but where it comes to more sophisticated commands such as:
the issue arises in the parameter of the
/TN
flag, trying to run this specific command through:We get an error back because the quotes were escaped, instead of successfully creating the task/running the command at all, what we're getting back is an error:
this happens because the command cmd_lib actually runs looks like:
SCHTASKS /Create /TN \"New Task\" /SC HOURLY /TR blah.exe /RL HIGHEST
<- Notice the escaped double quotesIs there anything we can do about it? I've tried to hack into the internals of the library with little to no success in that matter. any help will be appreciated.
EDIT: https://internals.rust-lang.org/t/std-process-on-windows-is-escaping-raw-literals-which-causes-problems-with-chaining-commands/8163/16?u=xpyder
https://users.rust-lang.org/t/std-process-is-escaping-a-raw-string-literal-when-i-dont-want-it-to/19441
Found the above threads, actually an issue which goes back to MS-DOS on windows, nothing you can really do about it :(