diff options
author | Eric Wong <normalperson@yhbt.net> | 2006-08-05 22:06:12 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2006-08-05 22:06:12 +0000 |
commit | dd4c6d45f20e0e5ec771263a3227f1f9bc5d3784 (patch) | |
tree | b3c1e8aeca397ebebbda438abbf53535f173831f | |
parent | 8e8d4fc6fd7a49c06f0a5ddd6396df2094454da5 (diff) | |
download | mpd-dd4c6d45f20e0e5ec771263a3227f1f9bc5d3784.tar.gz mpd-dd4c6d45f20e0e5ec771263a3227f1f9bc5d3784.tar.xz mpd-dd4c6d45f20e0e5ec771263a3227f1f9bc5d3784.zip |
buffer2array: fix for trailing sub-quoted text inside a quoted context
Also added a unit test to check for errors/bugs to make sure we
don't have regressions.
Bug found by Qball.
git-svn-id: https://svn.musicpd.org/mpd/trunk@4569 09075e82-0dd4-0310-85a5-a0d7c8717e4f
-rw-r--r-- | src/buffer2array.c | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/src/buffer2array.c b/src/buffer2array.c index 39fc29bc9..ecd01701b 100644 --- a/src/buffer2array.c +++ b/src/buffer2array.c @@ -34,10 +34,12 @@ int cstrtok(char *buffer, char *array[], const int max) array[i++] = ++c; while (*c != '\0') { if (*c == '\"') { - if (escape) + if (escape) { memmove(c - 1, c, strlen(c) + 1); - else { + if (*c == '"') + break; + } else { *(c++) = '\0'; break; } @@ -62,3 +64,35 @@ int cstrtok(char *buffer, char *array[], const int max) } return i; } + +#ifdef UNIT_TEST + +#include <stdio.h> +#include <string.h> +#include <assert.h> + +int main() +{ + char *a[4] = { NULL }; + char *b; + int i, max; + + b = strdup("lsinfo \"/some/dir/name \\\"test\\\"\""); + max = cstrtok(b, a, 4); + assert( !strcmp("lsinfo", a[0]) ); + assert( !strcmp("/some/dir/name \"test\"", a[1]) ); + + b = strdup("lsinfo \"/some/dir/name \\\"test\\\" something else\""); + max = cstrtok(b, a, 4); + assert( !strcmp("lsinfo", a[0]) ); + assert( !strcmp("/some/dir/name \"test\" something else", a[1]) ); + + b = strdup("lsinfo \"/some/dir\\\\name\""); + max = cstrtok(b, a, 4); + assert( !strcmp("lsinfo", a[0]) ); + assert( !strcmp("/some/dir\\name", a[1]) ); + + return 0; +} + +#endif |