2 ms·
You don't need to parse every little piece of syntactic sugar that is introduced by various shells. You're trying to produce something that will be parsed as a
by pyre 15y ago
You don't need to parse every little piece of syntactic sugar that is introduced by various shells. You're trying to produce something that will be parsed as a string literal. For the most part, non-alpha-numeric characters should just be escaped. If all non-[:alphanum:] characters were escaped regardless of need, I can't think of anything that would accidentally parse as anything dynamic in any of the shells out there.
Also, the most common case would be system(sprintf(...)). This should just pass the command onto the shell in compatibility mode, meaning most of the extra sugar should be disabled. Even all of zsh's string parsing sugar needs to be turned on (disabled by default).
Ignoring all of that, the most common thing that you want properly escaped would be:
- Semi-colon to prevent injection.
- Spaces to make sure that the string is parsed as a single arg.
- Quotes and double-quotes because you want them to be part of the argument text and not part of the shell's syntax.
Even that short list of requirements would be useful.