From 7e6fc1f1962608827688c8139cb6f00803c4f3ff Mon Sep 17 00:00:00 2001 From: Tiago R Date: Mon, 9 Oct 2023 13:56:49 +0000 Subject: [PATCH] fuck i owe almeida a donut now Signed-off-by: GitHub --- backend/src/templateFormatter.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/backend/src/templateFormatter.ts b/backend/src/templateFormatter.ts index 3f04fc76..a4a11b1d 100644 --- a/backend/src/templateFormatter.ts +++ b/backend/src/templateFormatter.ts @@ -538,11 +538,16 @@ const baseValues = { return math_constants[str.toLowerCase()] ?? ""; }, map(obj, key) { - if (typeof obj !== "object" || typeof key !== "string" || typeof obj === "function" || !obj) return ""; - if (Array.isArray(obj)) { - return obj.map((tobj) => tobj[key]); + return actualMap(obj, key); + + function actualMap(obj, key, depth = 0) { + if (depth > 5) return ""; + if (!obj || !key || typeof obj !== "object" || typeof key !== "string") return ""; + if (Array.isArray(obj)) { + return obj.map((tobj) => actualMap(tobj, key, depth + 1)); + } + return obj[key]; } - return obj[key]; }, cases(mod, ...cases) { if (cases.length === 0) return "";