From: Adam Dickmeiss Date: Thu, 15 Dec 2011 08:37:11 +0000 (+0100) Subject: Allow =val to be omitted for yaz_uri_to_array X-Git-Tag: v4.2.23~9 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=692cfa1de9dd855c1725db48f6d0a2cddcae9fcd;p=yaz-moved-to-github.git Allow =val to be omitted for yaz_uri_to_array Also, multiple &'s in sequence is treated as one. For example, &&a=b&&&c& is identical to a=b&c= . --- diff --git a/src/uri.c b/src/uri.c index 987b121..ecf1adc 100644 --- a/src/uri.c +++ b/src/uri.c @@ -138,31 +138,37 @@ int yaz_uri_to_array(const char *path, ODR o, char ***name, char ***val) for (no = 0; *path; no++) { - const char *p1 = strchr(path, '='); - size_t i = 0; - char *ret; - if (!p1) + while (*path == '&') + path++; + if (!*path) break; - (*name)[no] = (char *) odr_malloc(o, (p1-path)+1); - memcpy((*name)[no], path, p1-path); - (*name)[no][p1-path] = '\0'; + for (cp = path; *cp && *cp != '=' && *cp != '&'; cp++) + ; - path = p1 + 1; - p1 = strchr(path, '&'); - if (!p1) - p1 = strlen(path) + path; - (*val)[no] = ret = (char *) odr_malloc(o, p1 - path + 1); - while (*path && *path != '&') - { - size_t l = 3; - ret[i++] = decode_uri_char(path, &l); - path += l; - } - ret[i] = '\0'; + (*name)[no] = (char *) odr_malloc(o, (cp-path)+1); + memcpy((*name)[no], path, cp-path); + (*name)[no][cp-path] = '\0'; - if (*path) + path = cp; + if (*path == '=') + { + size_t i = 0; + char *ret; path++; + for (cp = path; *cp && *cp != '&'; cp++) + ; + (*val)[no] = ret = (char *) odr_malloc(o, cp - path + 1); + while (*path && *path != '&') + { + size_t l = 3; + ret[i++] = decode_uri_char(path, &l); + path += l; + } + ret[i] = '\0'; + } + else + (*val)[no] = odr_strdup(o, ""); } (*name)[no] = 0; (*val)[no] = 0;