From 7083bea56b75ee6c154f0090df611c096b403ed2 Mon Sep 17 00:00:00 2001
From: Sergey Lyubka <valenok@gmail.com>
Date: Tue, 28 Jan 2014 13:01:28 +0000
Subject: [PATCH] mg_parse_header(): allowing no spaces for comma-separated
 list

---
 mongoose.c  | 4 ++--
 unit_test.c | 4 +++-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/mongoose.c b/mongoose.c
index a7a3d1161..fde9ea941 100644
--- a/mongoose.c
+++ b/mongoose.c
@@ -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++;
     }
diff --git a/unit_test.c b/unit_test.c
index 13ce3f795..b3d034492 100644
--- a/unit_test.c
+++ b/unit_test.c
@@ -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;
 }
 
-- 
GitLab