aboutsummaryrefslogtreecommitdiff
path: root/libpkgconf/tuple.c
diff options
context:
space:
mode:
Diffstat (limited to 'libpkgconf/tuple.c')
-rw-r--r--libpkgconf/tuple.c39
1 files changed, 36 insertions, 3 deletions
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;
}