-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
Unexpected handling of combination of backslashes and spaces #14
Comments
try |
Yes, of course this correctly prints |
This package returns a string; the bounding quotes aren't part of it, so you just always include them. |
Quoting the string |
ah, sorry, early morning here. i'll take another look at this issue when i'm more awake. |
Thank you -- still quite possible I'm misunderstanding how to use it correctly. My comparison points are Python's This has led me to the following temporary solution for JavaScript on Unix-based systems (I'm aware that this is hugely non-performant given the use of import { spawnSync } from "child_process";
export default function quote(rawInput: string): string {
const result = spawnSync("printf", ["%q", rawInput], { encoding: "utf8" });
if (result.status === 0) {
return result.stdout;
} else {
throw new Error(
`printf failed with code ${result.status} and error: ${result.stderr}`,
);
}
} |
I might be misunderstanding the intended usage of shell-quote, but it seems like strings containing both backslashes and spaces are not handled properly:
Let's consider the string
foo \ bar
.quote(["foo \\ bar"])
returns'foo \\ bar'
, and in bash,echo 'foo \\ bar'
printsfoo \\ bar
.This failure case does not occur with the same string without spaces (
foo\bar
):quote(["foo\\bar"])
returnsfoo\\bar
, and in bash,echo foo\\bar
printsfoo\bar
.Here's a quick typescript file to reproduce with a few test cases:
The output of running that file is:
The text was updated successfully, but these errors were encountered: