From: Adam Dickmeiss Date: Thu, 22 Sep 2011 12:43:22 +0000 (+0200) Subject: Another fix for nmem_strsplit_escape X-Git-Tag: v4.2.16~1 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=474209f883ef0abea418e5fe2e3e2451b2ff3a0e;p=yaz-moved-to-github.git Another fix for nmem_strsplit_escape Double-escape was not encoded to escape. Test case in place. --- diff --git a/src/nmemsdup.c b/src/nmemsdup.c index a0fa637..75b6e85 100644 --- a/src/nmemsdup.c +++ b/src/nmemsdup.c @@ -105,11 +105,13 @@ void nmem_strsplit_escape(NMEM nmem, const char *delim, const char *dstr, char *dst, *src; (*darray)[i] = nmem_strdupn(nmem, cp0, cp - cp0); dst = src = (*darray)[i]; - for (; (*dst = *src) != '\0'; src++) + while (*src != '\0') { - if (*src != escape_char) - dst++; + if (*src == escape_char && src[1]) + src++; + *dst++ = *src++; } + *dst = '\0'; } i++; if (!collapse) diff --git a/test/test_nmem.c b/test/test_nmem.c index b2a0b7b..1fac283 100644 --- a/test/test_nmem.c +++ b/test/test_nmem.c @@ -96,16 +96,16 @@ void tst_nmem_strsplit(void) YAZ_CHECK(num > 2 && !strcmp(array[2], "b,")); YAZ_CHECK(num > 3 && !strcmp(array[3], "cd")); - nmem_strsplit_escape(nmem, ",", "\\,a,b\\,,cd", &array, &num, 0, '\\'); + nmem_strsplit_escape(nmem, ",", "\\,a,b\\,,c\\d", &array, &num, 0, '\\'); YAZ_CHECK(num == 3); YAZ_CHECK(num > 0 && !strcmp(array[0], ",a")); YAZ_CHECK(num > 1 && !strcmp(array[1], "b,")); YAZ_CHECK(num > 2 && !strcmp(array[2], "cd")); - nmem_strsplit_escape(nmem, ",", "\\,a,b\\,\\,cd", &array, &num, 0, '\\'); + nmem_strsplit_escape(nmem, ",", "\\,a,b\\,\\,c\\\\\\|d", &array, &num, 0, '\\'); YAZ_CHECK(num == 2); YAZ_CHECK(num > 0 && !strcmp(array[0], ",a")); - YAZ_CHECK(num > 1 && !strcmp(array[1], "b,,cd")); + YAZ_CHECK(num > 1 && !strcmp(array[1], "b,,c\\|d")); nmem_destroy(nmem); } @@ -113,6 +113,7 @@ void tst_nmem_strsplit(void) int main (int argc, char **argv) { YAZ_CHECK_INIT(argc, argv); + YAZ_CHECK_LOG(); tst_nmem_malloc(); tst_nmem_strsplit(); YAZ_CHECK_TERM;