Skip to content

Commit 9ca68e0

Browse files
t-ramzAnthony Ramirez
andauthored
Parse md json strings (#1347)
* Parse md json strings * parse execQuery params * move to direct only * make params an object * remove console log --------- Co-authored-by: Anthony Ramirez <[email protected]>
1 parent 9da6616 commit 9ca68e0

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

core/database/foxx/api/data_router.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function recordCreate(client, record, result) {
101101
}
102102

103103
if (record.md) {
104-
obj.md = record.md;
104+
obj.md = JSON.parse(record.md); // parse escaped JSON string TODO: this could be dangerous
105105
if (Array.isArray(obj.md)) throw [g_lib.ERR_INVALID_PARAM, "Metadata cannot be an array"];
106106
}
107107

@@ -463,7 +463,7 @@ function recordUpdate(client, record, result) {
463463
obj.md_err_msg = null;
464464
obj.md_err = false;
465465
} else if (record.md) {
466-
obj.md = record.md;
466+
obj.md = JSON.parse(record.md);
467467
if (Array.isArray(obj.md)) {
468468
throw [g_lib.ERR_INVALID_PARAM, "Metadata cannot be an array"];
469469
}

core/database/foxx/api/query_router.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,12 @@ router
301301
.summary("List client saved queries")
302302
.description("List client saved queries");
303303

304-
function execQuery(client, mode, published, query) {
304+
function execQuery(client, mode, published, orig_query) {
305305
var col_chk = true,
306306
ctxt = client._id;
307-
307+
let query = {
308+
...orig_query,
309+
};
308310
if (!published) {
309311
// For searches over private data, must perform access checks based on owner field and client id
310312

@@ -533,7 +535,11 @@ router
533535
try {
534536
const client = g_lib.getUserFromClientID_noexcept(req.queryParams.client);
535537

536-
var results = execQuery(client, req.body.mode, req.body.published, req.body);
538+
const query = {
539+
...req.body,
540+
params: JSON.parse(req.body.params),
541+
};
542+
var results = execQuery(client, req.body.mode, req.body.published, query);
537543

538544
res.send(results);
539545
} catch (e) {
@@ -549,7 +555,7 @@ router
549555
qry_begin: joi.string().required(),
550556
qry_end: joi.string().required(),
551557
qry_filter: joi.string().optional().allow(""),
552-
params: joi.object().required(),
558+
params: joi.string().required(),
553559
limit: joi.number().integer().required(),
554560
})
555561
.required(),

core/server/DatabaseAPI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1292,7 +1292,7 @@ void DatabaseAPI::generalSearch(const Auth::SearchRequest &a_request,
12921292
payload["qry_begin"] = qry_begin;
12931293
payload["qry_end"] = qry_end;
12941294
payload["qry_filter"] = qry_filter;
1295-
payload["params"] = params;
1295+
payload["params"] = "{" + params + "}";
12961296
payload["limit"] = to_string(cnt);
12971297

12981298
string body = payload.dump(-1, ' ', true);

0 commit comments

Comments
 (0)