mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-29 21:08:24 +00:00
Proper handling {} in JSON array + unit test
This commit is contained in:
1 parent
fe0d2272f6
commit
6085998d57
3 files changed
+6
No files matched your search
@@ -2532,6 +2532,7 @@ int mg_json_get(struct mg_str json, const char *path, int *toklen) {
|
|||||||
} else if (c == '}') { // Empty object
|
} else if (c == '}') { // Empty object
|
||||||
MG_EOO('}');
|
MG_EOO('}');
|
||||||
expecting = S_COMMA_OR_EOO;
|
expecting = S_COMMA_OR_EOO;
|
||||||
|
if (depth == ed && ei >= 0) ci++;
|
||||||
} else {
|
} else {
|
||||||
return MG_JSON_INVALID;
|
return MG_JSON_INVALID;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,6 +182,7 @@ int mg_json_get(struct mg_str json, const char *path, int *toklen) {
|
|||||||
} else if (c == '}') { // Empty object
|
} else if (c == '}') { // Empty object
|
||||||
MG_EOO('}');
|
MG_EOO('}');
|
||||||
expecting = S_COMMA_OR_EOO;
|
expecting = S_COMMA_OR_EOO;
|
||||||
|
if (depth == ed && ei >= 0) ci++;
|
||||||
} else {
|
} else {
|
||||||
return MG_JSON_INVALID;
|
return MG_JSON_INVALID;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2792,6 +2792,10 @@ static void test_json(void) {
|
|||||||
json = mg_str("{\"a\":1,\"b\":[1,2]}");
|
json = mg_str("{\"a\":1,\"b\":[1,2]}");
|
||||||
ASSERT(mg_json_get(json, "$.a", &n) == 5 && n == 1);
|
ASSERT(mg_json_get(json, "$.a", &n) == 5 && n == 1);
|
||||||
ASSERT(mg_json_get(json, "$.a[0]", &n) < 0 && n == 0);
|
ASSERT(mg_json_get(json, "$.a[0]", &n) < 0 && n == 0);
|
||||||
|
|
||||||
|
ASSERT(mg_json_get_long(mg_str("[0, 42]"), "$[1]", 0) == 42);
|
||||||
|
ASSERT(mg_json_get_long(mg_str("[[], 42]"), "$[1]", 0) == 42);
|
||||||
|
ASSERT(mg_json_get_long(mg_str("[{}, 42]"), "$[1]", 0) == 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void resp_rpc(struct mg_rpc_req *r) {
|
static void resp_rpc(struct mg_rpc_req *r) {
|
||||||
|
|||||||
Reference in new issue
Block a user