Fix #2345 - json parsing of arrays of objects

This commit is contained in:
cpq committed 2023-08-16 22:09:45 +01:00
1 parent 66e022c454
commit 58886a9693
3 files changed
+30 -10

No files matched your search

+12
View File
@@ -2939,6 +2939,18 @@ static void test_json(void) {
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);
json = mg_str("[{\"a\":1},{\"a\":2}]");
ASSERT(mg_json_get_long(json, "$[0]", -1) == -1);
ASSERT(mg_json_get_long(json, "$[0].a", -1) == 1);
ASSERT(mg_json_get_long(json, "$[1].a", -1) == 2);
ASSERT(mg_json_get_long(json, "$[2].a", -1) == -1);
json = mg_str("[{\"a1\":1},{\"a\":2}]");
ASSERT(mg_json_get_long(json, "$[0]", -1) == -1);
ASSERT(mg_json_get_long(json, "$[0].a", -1) == -1);
ASSERT(mg_json_get_long(json, "$[1].a", -1) == 2);
ASSERT(mg_json_get_long(json, "$[2].a", -1) == -1);
}
static void resp_rpc(struct mg_rpc_req *r) {