Commit 7083bea5 authored by Sergey Lyubka's avatar Sergey Lyubka

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

parent 3dffd760
......@@ -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++;
}
......
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment