mg_parse_header(): allowing no spaces for comma-separated list

This commit is contained in:
Sergey Lyubka committed 2014-01-28 13:01:28 +00:00
1 parent 3dffd7604a
commit 7083bea56b
2 files changed
+5 -3

No files matched your search

+2 -2
View File
@@ -3042,7 +3042,7 @@ int parse_header(const char *str, int str_len, const char *var_name, char *buf,
// Find where variable starts
for (s = str; s != NULL && s + n < end; s++) {
if ((s == str || s[-1] == ' ') && s[n] == '=' &&
if ((s == str || s[-1] == ' ' || s[-1] == ',') && s[n] == '=' &&
!memcmp(s, var_name, n)) break;
}
@@ -3050,7 +3050,7 @@ int parse_header(const char *str, int str_len, const char *var_name, char *buf,
s += n + 1;
if (*s == '"' || *s == '\'') ch = *s++;
p = s;
while (p < end && p[0] != ch && len < (int) buf_size) {
while (p < end && p[0] != ch && p[0] != ',' && len < (int) buf_size) {
if (p[0] == '\\' && p[1] == ch) p++;
buf[len++] = *p++;
}
+3 -1
View File
@@ -322,7 +322,7 @@ static const char *test_base64_encode(void) {
static const char *test_mg_parse_header(void) {
const char *str = "xx=1 kl yy, ert=234 kl=123, "
"ii=\"12\\\"34\" zz='aa bb', gf=\"xx d=1234";
"ii=\"12\\\"34\" zz='aa bb',tt=2,gf=\"xx d=1234";
char buf[10];
ASSERT(mg_parse_header(str, "yy", buf, sizeof(buf)) == 0);
ASSERT(mg_parse_header(str, "ert", buf, sizeof(buf)) == 3);
@@ -344,6 +344,8 @@ static const char *test_mg_parse_header(void) {
ASSERT(strcmp(buf, "1") == 0);
ASSERT(mg_parse_header(str, "ii", buf, sizeof(buf)) == 5);
ASSERT(strcmp(buf, "12\"34") == 0);
ASSERT(mg_parse_header(str, "tt", buf, sizeof(buf)) == 1);
ASSERT(strcmp(buf, "2") == 0);
return NULL;
}