mirror of
https://github.com/cesanta/mongoose.git
synced 2024-11-24 19:19:00 +08:00
Merge pull request #1642 from cesanta/fix-json
Fix json's MG_EOO in nested objects
This commit is contained in:
commit
7587f8212e
12
mongoose.c
12
mongoose.c
@ -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++) {
|
||||
|
12
src/json.c
12
src/json.c
@ -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++) {
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user