Skip to content
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

Is this escaping right? #15

Open
tommedema opened this issue Apr 18, 2024 · 2 comments
Open

Is this escaping right? #15

tommedema opened this issue Apr 18, 2024 · 2 comments

Comments

@tommedema
Copy link

tommedema commented Apr 18, 2024

Consider this case:

const cmd = `eval ${quote(['find /home -type f -name "*.json" -exec ls -l {} \\;'])} </dev/null 2>&1;`
console.log(cmd)

which results in:

eval 'find / -type f -name "*.json" -exec ls -l {} \\;' </dev/null 2>&1;

which results in:

find: missing argument to `-exec'

Yet when you run the command directly in the shell it works fine because it would be:

eval 'find / -type f -name "*.json" -exec ls -l {} \;' </dev/null 2>&1;

Am I misunderstanding what shell-quote is or is this a bug?

@tommedema
Copy link
Author

tommedema commented Apr 18, 2024

fyi the issue doesn't occur with https://www.npmjs.com/package/shlex or python's shlex, which escape it as:

eval 'find / -type f -name "*.json" -exec ls -l {} \;' </dev/null 2>&1;

@ljharb
Copy link
Owner

ljharb commented Apr 23, 2024

Your example doesn't use shell-quote?

Per the readme, the library's parse function takes a command. When I do parse(`eval 'find / -type f -name "*.json" -exec ls -l {} \;' </dev/null 2>&1;`), i get an array:

[
  'eval',
  'find / -type f -name "*.json" -exec ls -l {} ;',
  { op: '<' },
  '/dev/null',
  '2',
  { op: '>&' },
  '1',
  { op: ';' }
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants