From b9ec274bed571db9c705b65bb8c0bb6409c34fc4 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Wed, 21 Dec 2016 23:12:05 +0100 Subject: git-receiver: moved shell quote function to common --- src/common/utils.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/common/utils.c') diff --git a/src/common/utils.c b/src/common/utils.c index f745146..9061e40 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -643,3 +643,27 @@ bc_trie_foreach(bc_trie_t *trie, bc_trie_foreach_func_t func, bc_trie_foreach_node(trie->root, str, func, user_data); bc_string_free(str, true); } + + +char* +bc_shell_quote(const char *command) +{ + bc_string_t *rv = bc_string_new(); + bc_string_append_c(rv, '\''); + if (command != NULL) { + for (size_t i = 0; i < strlen(command); i++) { + switch (command[i]) { + case '!': + bc_string_append(rv, "'\\!'"); + break; + case '\'': + bc_string_append(rv, "'\\''"); + break; + default: + bc_string_append_c(rv, command[i]); + } + } + } + bc_string_append_c(rv, '\''); + return bc_string_free(rv, false); +} -- cgit v1.2.3-18-g5258