From 2c2eb69ae71aa758f4270598c8812ff59b3a651a Mon Sep 17 00:00:00 2001 From: Mel O'Hagan Date: Tue, 17 May 2022 12:11:43 +0100 Subject: [PATCH] Improve parseQueryParams regex --- packages/server/src/integrations/mongodb.ts | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/packages/server/src/integrations/mongodb.ts b/packages/server/src/integrations/mongodb.ts index ae6754907b..3d851399f6 100644 --- a/packages/server/src/integrations/mongodb.ts +++ b/packages/server/src/integrations/mongodb.ts @@ -113,29 +113,20 @@ module MongoDBModule { } parseQueryParams(params: string, mode: string) { - let queryParams = params.split(/(?<=(},)).*{/g) - let group1 = queryParams[0] - let group2 = queryParams[2] - let group3 = queryParams[4] - if (group1) { - group1 = JSON.parse(group1.replace(/,+$/, "")) - } - if (group2) { - group2 = JSON.parse("{" + group2.replace(/,+$/, "")) - } - if (group3) { - group3 = JSON.parse("{" + group3.replace(/,+$/, "")) - } + let queryParams = params.split(/(?<=}),[\n\s]*(?={)/g) + let group1 = queryParams[0] ? JSON.parse(queryParams[0]) : {} + let group2 = queryParams[1] ? JSON.parse(queryParams[1]) : {} + let group3 = queryParams[2] ? JSON.parse(queryParams[2]) : {} if (mode === "update") { return { filter: group1, update: group2, - options: group3 ?? {}, + options: group3, } } return { filter: group1, - options: group2 ?? {}, + options: group2, } }