From 95fee14dfa5bd3896c510077af36ea371a9a2975 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 26 Oct 2018 13:47:53 +0300 Subject: Merge with 1.5.4 upstream package version --- libpkgconf/tuple.c | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'libpkgconf/tuple.c') diff --git a/libpkgconf/tuple.c b/libpkgconf/tuple.c index a4b4250..6a610a1 100644 --- a/libpkgconf/tuple.c +++ b/libpkgconf/tuple.c @@ -136,6 +136,34 @@ pkgconf_tuple_find_delete(pkgconf_list_t *list, const char *key) } } +static char * +dequote(const char *value) +{ + char *buf = calloc((strlen(value) + 1) * 2, 1); + char *bptr = buf; + const char *i; + char quote = 0; + +/* + * Fix the broken quote escaping (issue #12 is reported). + */ + if (*value == '\'' || *value == '"') + quote = *value; + + for (i = value; *i != '\0'; i++) + { + if (*i == '\\' && quote && *(i + 1) == quote) + { + i++; + *bptr++ = *i; + } + else if (*i != quote) + *bptr++ = *i; + } + + return buf; +} + /* * !doc * @@ -154,20 +182,25 @@ pkgconf_tuple_find_delete(pkgconf_list_t *list, const char *key) pkgconf_tuple_t * pkgconf_tuple_add(const pkgconf_client_t *client, pkgconf_list_t *list, const char *key, const char *value, bool parse) { + char *dequote_value; pkgconf_tuple_t *tuple = calloc(sizeof(pkgconf_tuple_t), 1); pkgconf_tuple_find_delete(list, key); - PKGCONF_TRACE(client, "adding tuple to @%p: %s => %s (parsed? %d)", list, key, value, parse); + dequote_value = dequote(value); + + PKGCONF_TRACE(client, "adding tuple to @%p: %s => %s (parsed? %d)", list, key, dequote_value, parse); tuple->key = strdup(key); if (parse) - tuple->value = pkgconf_tuple_parse(client, list, value); + tuple->value = pkgconf_tuple_parse(client, list, dequote_value); else - tuple->value = strdup(value); + tuple->value = strdup(dequote_value); pkgconf_node_insert(&tuple->iter, tuple, list); + free(dequote_value); + return tuple; } -- cgit v1.1