Merge pull request #1642 from cesanta/fix-json

Fix json's MG_EOO in nested objects
This commit is contained in:
Sergey Lyubka 2022-07-25 10:53:30 +01:00 committed by GitHub
commit 7587f8212e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 13 deletions

View File

@ -2494,12 +2494,12 @@ int mg_json_get(const char *s, int len, const char *path, int *toklen) {
// In the ascii table, the distance between `[` and `]` is 2.
// Ditto for `{` and `}`. Hence +2 in the code below.
#define MG_EOO(x) \
do { \
if (depth == ed && ci != ei) return MG_JSON_NOT_FOUND; \
if (c != nesting[depth - 1] + 2) return MG_JSON_INVALID; \
depth--; \
MG_CHECKRET(x); \
#define MG_EOO(x) \
do { \
if (depth == ed && (ci != ei || ci < 0)) return MG_JSON_NOT_FOUND; \
if (c != nesting[depth - 1] + 2) return MG_JSON_INVALID; \
depth--; \
MG_CHECKRET(x); \
} while (0)
for (i = 0; i < len; i++) {

View File

@ -58,12 +58,12 @@ int mg_json_get(const char *s, int len, const char *path, int *toklen) {
// In the ascii table, the distance between `[` and `]` is 2.
// Ditto for `{` and `}`. Hence +2 in the code below.
#define MG_EOO(x) \
do { \
if (depth == ed && ci != ei) return MG_JSON_NOT_FOUND; \
if (c != nesting[depth - 1] + 2) return MG_JSON_INVALID; \
depth--; \
MG_CHECKRET(x); \
#define MG_EOO(x) \
do { \
if (depth == ed && (ci != ei || ci < 0)) return MG_JSON_NOT_FOUND; \
if (c != nesting[depth - 1] + 2) return MG_JSON_INVALID; \
depth--; \
MG_CHECKRET(x); \
} while (0)
for (i = 0; i < len; i++) {

View File

@ -2317,7 +2317,7 @@ static void test_get_header_var(void) {
static void test_json(void) {
const char *s;
const char *s1 = "{\"a\":{},\"b\":7,\"c\":[[],2]}";
const char *s2 = "{\"a\":{\"b1\":{}},\"c\":7}";
const char *s2 = "{\"a\":{\"b1\":{}},\"c\":7,\"d\":{\"b2\":{}}}";
int n, n1 = (int) strlen(s1), n2 = (int) strlen(s2);
ASSERT(mg_json_get(" true ", 6, "", &n) == MG_JSON_INVALID);