mirror of
https://github.com/cesanta/mongoose.git
synced 2025-06-07 17:42:30 +08:00
Fix #416
This commit is contained in:
parent
03a82ef848
commit
e4ad3010be
10
mongoose.c
10
mongoose.c
@ -4105,23 +4105,23 @@ static int is_dav_request(const struct connection *conn) {
|
||||
|
||||
static int parse_header(const char *str, int str_len, const char *var_name,
|
||||
char *buf, size_t buf_size) {
|
||||
int ch = ' ', len = 0, n = strlen(var_name);
|
||||
int ch = ' ', ch1 = ',', len = 0, n = strlen(var_name);
|
||||
const char *p, *end = str + str_len, *s = NULL;
|
||||
|
||||
if (buf != NULL && buf_size > 0) buf[0] = '\0';
|
||||
|
||||
// Find where variable starts
|
||||
for (s = str; s != NULL && s + n < end; s++) {
|
||||
if ((s == str || s[-1] == ' ' || s[-1] == ',') && s[n] == '=' &&
|
||||
if ((s == str || s[-1] == ch || s[-1] == ch1) && s[n] == '=' &&
|
||||
!memcmp(s, var_name, n)) break;
|
||||
}
|
||||
|
||||
if (s != NULL && &s[n + 1] < end) {
|
||||
s += n + 1;
|
||||
if (*s == '"' || *s == '\'') ch = *s++;
|
||||
if (*s == '"' || *s == '\'') ch = ch1 = *s++;
|
||||
p = s;
|
||||
while (p < end && p[0] != ch && p[0] != ',' && len < (int) buf_size) {
|
||||
if (p[0] == '\\' && p[1] == ch) p++;
|
||||
while (p < end && p[0] != ch && p[0] != ch1 && len < (int) buf_size) {
|
||||
if (ch == ch1 && p[0] == '\\' && p[1] == ch) p++;
|
||||
buf[len++] = *p++;
|
||||
}
|
||||
if (len >= (int) buf_size || (ch != ' ' && *p != ch)) {
|
||||
|
@ -306,9 +306,9 @@ 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, "
|
||||
const char *str = "xx=1 kl yy, ert=234 kl=123, uri=\"/?name=x,y\", "
|
||||
"ii=\"12\\\"34\" zz='aa bb',tt=2,gf=\"xx d=1234";
|
||||
char buf[10];
|
||||
char buf[20];
|
||||
ASSERT(mg_parse_header(str, "yy", buf, sizeof(buf)) == 0);
|
||||
ASSERT(mg_parse_header(str, "ert", buf, sizeof(buf)) == 3);
|
||||
ASSERT(strcmp(buf, "234") == 0);
|
||||
@ -331,6 +331,7 @@ static const char *test_mg_parse_header(void) {
|
||||
ASSERT(strcmp(buf, "12\"34") == 0);
|
||||
ASSERT(mg_parse_header(str, "tt", buf, sizeof(buf)) == 1);
|
||||
ASSERT(strcmp(buf, "2") == 0);
|
||||
ASSERT(mg_parse_header(str, "uri", buf, sizeof(buf)) == 10);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user