aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2006-10-10 19:37:32 +0000
committerEric Wong <normalperson@yhbt.net>2006-10-10 19:37:32 +0000
commit4c80121bba4330f3645db1812d8e845056065ebe (patch)
tree20cc71781a49c8529fb676dfa5c4b2e606111338 /src
parente0a8c179575648afedd0d2088d1b542c5427fcf2 (diff)
downloadmpd-4c80121bba4330f3645db1812d8e845056065ebe.tar.gz
mpd-4c80121bba4330f3645db1812d8e845056065ebe.tar.xz
mpd-4c80121bba4330f3645db1812d8e845056065ebe.zip
buffer2array: extra unit tests (for PHP magic quote escapes)
Make the unit tests compile correctly without using xstrdup. Also, use "static inline" instead of "inline static": certain compilers or cflags are likely to complain about the latter. git-svn-id: https://svn.musicpd.org/mpd/trunk@4892 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src')
-rw-r--r--src/buffer2array.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/src/buffer2array.c b/src/buffer2array.c
index fdcef790f..255199d68 100644
--- a/src/buffer2array.c
+++ b/src/buffer2array.c
@@ -24,7 +24,7 @@
#include <ctype.h>
-inline static
+static inline
int
isWhiteSpace(char c)
{
@@ -43,7 +43,7 @@ int buffer2array(char *buffer, char *array[], const int max)
if (*c == '\"') {
*(c++) = '\0';
break;
- }
+ }
else if (*(c++) == '\\' && *c != '\0') {
memmove(c - 1, c, strlen(c) + 1);
}
@@ -76,44 +76,56 @@ int main()
{
char *a[4] = { NULL };
char *b;
- int i, max;
+ int max;
- b = xstrdup("lsinfo \"/some/dir/name \\\"test\\\"\"");
+ b = strdup("lsinfo \"/some/dir/name \\\"test\\\"\"");
max = buffer2array(b, a, 4);
assert( !strcmp("lsinfo", a[0]) );
assert( !strcmp("/some/dir/name \"test\"", a[1]) );
assert( !a[2] );
- b = xstrdup("lsinfo \"/some/dir/name \\\"test\\\" something else\"");
+ b = strdup("lsinfo \"/some/dir/name \\\"test\\\" something else\"");
max = buffer2array(b, a, 4);
assert( !strcmp("lsinfo", a[0]) );
assert( !strcmp("/some/dir/name \"test\" something else", a[1]) );
assert( !a[2] );
- b = xstrdup("lsinfo \"/some/dir\\\\name\"");
+ b = strdup("lsinfo \"/some/dir\\\\name\"");
max = buffer2array(b, a, 4);
assert( !strcmp("lsinfo", a[0]) );
assert( !strcmp("/some/dir\\name", a[1]) );
assert( !a[2] );
- b = xstrdup("lsinfo \"/some/dir name\"");
+ b = strdup("lsinfo \"/some/dir name\"");
max = buffer2array(b, a, 4);
assert( !strcmp("lsinfo", a[0]) );
assert( !strcmp("/some/dir name", a[1]) );
assert( !a[2] );
- b = xstrdup("lsinfo \"\\\"/some/dir\\\"\"");
+ b = strdup("lsinfo \"\\\"/some/dir\\\"\"");
max = buffer2array(b, a, 4);
assert( !strcmp("lsinfo", a[0]) );
assert( !strcmp("\"/some/dir\"", a[1]) );
assert( !a[2] );
- b = xstrdup("lsinfo \"\\\"/some/dir\\\" x\"");
+ b = strdup("lsinfo \"\\\"/some/dir\\\" x\"");
max = buffer2array(b, a, 4);
assert( !strcmp("lsinfo", a[0]) );
assert( !strcmp("\"/some/dir\" x", a[1]) );
assert( !a[2] );
+ b = strdup("lsinfo \"single quote\\'d from php magicquotes\"");
+ max = buffer2array(b, a, 4);
+ assert( !strcmp("lsinfo", a[0]) );
+ assert( !strcmp("single quote\'d from php magicquotes", a[1]) );
+ assert( !a[2] );
+
+ b = strdup("lsinfo \"double quote\\\"d from php magicquotes\"");
+ max = buffer2array(b, a, 4);
+ assert( !strcmp("lsinfo", a[0]) );
+ assert( !strcmp("double quote\"d from php magicquotes", a[1]) );
+ assert( !a[2] );
+
return 0;
}