Bug #118
Single quotes in append() don't work, or: goddamn quoting
| Status: | Assigned | Start: | 12/13/2009 | |
| Priority: | Normal | Due date: | ||
| Assigned to: | % Done: | 0% |
||
| Category: | Contrib | |||
| Target version: | 1.1 | |||
Description
For some reason fabric.contrib.files.append tries to escape single-quotes in order to behave better given that it wraps the text to append in single quotes — despite this not being legal Bash syntax (says right in the manpage, can’t have single quotes between single quotes, even if it’s escaped with a backslash.)
If we attempt to reverse this to use double-quotes (meaning wrap in, and escape, double-quotes) then we run into problems due to how run/sudo do their own auto-escaping of quotes (mostly, I think, a nesting problem — one ends up with the backslash doubled up, and so thus the innermost, single double-quote ends up not truly escaped.)
I think this is symptomatic of a larger problem: quoting is freakin' difficult. It would be easier for us if we never did any auto-escaping at all, but there are at least some spots where that would make life very difficult for some use cases / users.
Perhaps any client code of run/sudo (such as append) should be barred from auto-escaping — leave it on for operations and make everything else subject to the “if you use quotes in your strings, be careful”.
History
Updated by Jeff Forcier 259 days ago
tswicegood’s fork, like another older (and since deleted) fork, includes the single-to-double quote change in the files module. At the very least, check with him for a test case where the existing works-for-me solution is broken, so that any future solution can be tested on both BSD/OS X as well as Linux.
Updated by Jeff Forcier 138 days ago
tip from sophacles on IRC: use pipes.quote. It’s undocumented unfortunately, but does appear to do at least some of the quoting we do ourselves.
One problem with quoting in general is it’s really two-fold: help avoid actually broken code at the run/sudo level, and also to avoid users having to think about quoting when using the higher level functions — especially ones using programs whose arguments themselves might need escaping/quoting, such as sed or grep.
That said, I imagine the only way to have any actual sanity may be to remove all quoting outside of run/sudo and slap pipes.quote inside it and hope that doesn’t make use of eg contrib.files.* a big pain. Will have to check this out.
Also available in: Atom