From 0e4748003e088b314d3cdf92d7ca12cb3e96e5a3 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 21 Sep 2020 23:19:45 +0100 Subject: [PATCH] Updates as per review comments. --- .../server/src/middleware/joi-validator.js | 25 ++++++++++--------- packages/server/src/workflows/thread.js | 4 +-- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/packages/server/src/middleware/joi-validator.js b/packages/server/src/middleware/joi-validator.js index b204d70c84..7ded06fe81 100644 --- a/packages/server/src/middleware/joi-validator.js +++ b/packages/server/src/middleware/joi-validator.js @@ -1,18 +1,19 @@ function validate(schema, property) { // Return a Koa middleware function return (ctx, next) => { - if (schema) { - let params = - ctx[property] != null - ? ctx[property] - : ctx.request[property] != null - ? ctx.request[property] - : null - const { error } = schema.validate(params) - if (error) { - ctx.throw(400, `Invalid ${property} - ${error.message}`) - return - } + if (!schema) { + return next() + } + let params = null + if (ctx[property] != null) { + params = ctx[property] + } else if (ctx.request[property] != null) { + params = ctx.request[property] + } + const { error } = schema.validate(params) + if (error) { + ctx.throw(400, `Invalid ${property} - ${error.message}`) + return } return next() } diff --git a/packages/server/src/workflows/thread.js b/packages/server/src/workflows/thread.js index 7fa0edc7db..1b83a05a39 100644 --- a/packages/server/src/workflows/thread.js +++ b/packages/server/src/workflows/thread.js @@ -10,8 +10,8 @@ function cleanMustache(string) { "]": "", } let regex = new RegExp(/{{[^}}]*}}/g) - let match - while ((match = regex.exec(string)) !== null) { + let matches = [...string.matchAll(regex)] + for (let match of matches) { let baseIdx = string.indexOf(match) for (let key of Object.keys(charToReplace)) { let idxChar = match[0].indexOf(key)