Merge pull request #5931 from Budibase/fix/5613-5387

Improve parseQueryParams regex
This commit is contained in:
melohagan 2022-05-17 14:54:58 +01:00 committed by GitHub
commit 09b5166aba
1 changed files with 6 additions and 15 deletions

View File

@ -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,
}
}