Help to copy the thing properly quoted for the shell safety. * any single quote is replaced with '\'', any exclamation point * is replaced with '\!', and the whole thing is enclosed in a * single quote pair. * * E.g. * original sq_quote result * name ==> name ==> 'name' * a b ==> a b ==> 'a b' * a'b ==> a'\''b ==> 'a'\''b' * a!b ==> a'\!'b
| 26 | * a!b ==> a'\!'b ==> 'a'\!'b' |
| 27 | */ |
| 28 | void sq_quote_buf(struct strbuf *dst, const char *src) |
| 29 | { |
| 30 | char *to_free = NULL; |
| 31 | |
| 32 | if (dst->buf == src) |
| 33 | to_free = strbuf_detach(dst, NULL); |
| 34 | |
| 35 | strbuf_addch(dst, '\''); |
| 36 | while (*src) { |
| 37 | size_t len = strcspn(src, "'!"); |
| 38 | strbuf_add(dst, src, len); |
| 39 | src += len; |
| 40 | while (need_bs_quote(*src)) { |
| 41 | strbuf_addstr(dst, "'\\"); |
| 42 | strbuf_addch(dst, *src++); |
| 43 | strbuf_addch(dst, '\''); |
| 44 | } |
| 45 | } |
| 46 | strbuf_addch(dst, '\''); |
| 47 | free(to_free); |
| 48 | } |
| 49 | |
| 50 | void sq_quote_buf_pretty(struct strbuf *dst, const char *src) |
| 51 | { |
no test coverage detected