Skip to content

Commit

Permalink
Correct condition check sequence for the prev fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cpq committed Aug 29, 2022
1 parent 0661f59 commit 7f30c01
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions mongoose.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7f30c01

Please sign in to comment.