From 7f30c01c586dd2a9e1bf4957adf17ee035c9749e Mon Sep 17 00:00:00 2001 From: cpq Date: Mon, 29 Aug 2022 13:01:56 +0100 Subject: [PATCH] Correct condition check sequence for the prev fix --- mongoose.c | 7 ++++--- src/json.c | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/mongoose.c b/mongoose.c index 88f856b2..fa650bac 100644 --- a/mongoose.c +++ b/mongoose.c @@ -2563,13 +2563,14 @@ int mg_json_get(struct mg_str json, const char *path, int *toklen) { case S_KEY: if (c == '"') { int n = mg_pass_string(&s[i + 1], len - i - 1); + printf("K %s %d %d %d [%.*s]\n", path, pos, n, i, n + 2, s + i); if (n < 0) return n; if (i + 1 + n >= len) return MG_JSON_NOT_FOUND; - // printf("K[%.*s] %d %d %d\n", n, &s[i + 1], n, depth, ed); + printf("K %s [%.*s] %d %d %d\n", path, n, &s[i + 1], n, depth, ed); if (depth == ed && path[pos - 1] == '.' && + strncmp(&s[i + 1], &path[pos], (size_t) n) == 0 && (path[pos + n] == '\0' || path[pos + n] == '.' || - path[pos + n] == '[') && - strncmp(&s[i + 1], &path[pos], (size_t) n) == 0) { + path[pos + n] == '[')) { pos += n; } i += n + 1; diff --git a/src/json.c b/src/json.c index c5da6853..79ade132 100644 --- a/src/json.c +++ b/src/json.c @@ -167,13 +167,14 @@ int mg_json_get(struct mg_str json, const char *path, int *toklen) { case S_KEY: if (c == '"') { int n = mg_pass_string(&s[i + 1], len - i - 1); + printf("K %s %d %d %d [%.*s]\n", path, pos, n, i, n + 2, s + i); if (n < 0) return n; if (i + 1 + n >= len) return MG_JSON_NOT_FOUND; - // printf("K[%.*s] %d %d %d\n", n, &s[i + 1], n, depth, ed); + printf("K %s [%.*s] %d %d %d\n", path, n, &s[i + 1], n, depth, ed); if (depth == ed && path[pos - 1] == '.' && + strncmp(&s[i + 1], &path[pos], (size_t) n) == 0 && (path[pos + n] == '\0' || path[pos + n] == '.' || - path[pos + n] == '[') && - strncmp(&s[i + 1], &path[pos], (size_t) n) == 0) { + path[pos + n] == '[')) { pos += n; } i += n + 1;