Open bdbaddog opened 6 years ago
Looks like the code has changed here - the collections of special
no longer includes parens, but I think the underlying comment is correct - since single and double quotes differ somewhat for POSIX shells, the escaped string should be forced to be single-quoted, not double-quoted. shlex.quote
does this (after using a regex to not-bother if there are no characters that actually need escaping):
return "'" + s.replace("'", "'\"'\"'") + "'"
@mwichmann Should we switch to use shlex.quote?
I probably would - it's not "portable", but since it's only intended for the Platform/posix module, that's not a problem.
A quick change - from shlex import quote as escape
- doesn't break any of the obvious tests. Update: it breaks one non-obvious one - test/GetBuildFailures/serial.py
. In this case the test is expecting oddly quoted things, and now not getting them. I think the test is silly (i.e. it was coded to the implementation, not necessarily to what the result should be), but now I'm a bit worried someone else might expect this too...
Note that the problem complained about here (escaping of parens) was probably fixed by ed53a2e548, which referenced a different issue, #2225, so I think we can close this in any case, up to @bdbaddog whether we further switch to using the (presumably) more tested routine from shlex.
This issue was originally created at: 2011-05-25 02:58:29. This issue was reported by:
sesarr
. sesarr said at 2011-05-25 02:58:29$ echo '()' # OK ()