From 204a8619ae6d401e093e2b8353de6d8b5071d10e Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Sat, 21 Aug 2021 01:05:34 +0300 Subject: [PATCH] Fix nested tag limiter --- backend/src/plugins/Tags/util/renderTagBody.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/backend/src/plugins/Tags/util/renderTagBody.ts b/backend/src/plugins/Tags/util/renderTagBody.ts index 90efffe3..de175d73 100644 --- a/backend/src/plugins/Tags/util/renderTagBody.ts +++ b/backend/src/plugins/Tags/util/renderTagBody.ts @@ -5,16 +5,17 @@ import { renderRecursively, StrictMessageContent } from "../../../utils"; import { TagsPluginType, TTag } from "../types"; import { findTagByName } from "./findTagByName"; +const MAX_TAG_FN_CALLS = 25; + export async function renderTagBody( pluginData: GuildPluginData, body: TTag, args: TemplateSafeValue[] = [], extraData = {}, subTagPermissionMatchParams?: ExtendedMatchParams, + tagFnCallsObj = { calls: 0 }, ): Promise { const dynamicVars = {}; - const maxTagFnCalls = 25; - let tagFnCalls = 0; const data = new TemplateSafeValueContainer({ args, @@ -33,7 +34,7 @@ export async function renderTagBody( return dynamicVars[name] == null ? "" : dynamicVars[name]; }, tag: async (name, ...subTagArgs) => { - if (tagFnCalls++ > maxTagFnCalls) return "\\_recursion\\_"; + if (++tagFnCallsObj.calls > MAX_TAG_FN_CALLS) return ""; if (typeof name !== "string") return ""; if (name === "") return ""; @@ -47,7 +48,14 @@ export async function renderTagBody( return ""; } - const rendered = await renderTagBody(pluginData, subTagBody, subTagArgs, extraData, subTagPermissionMatchParams); + const rendered = await renderTagBody( + pluginData, + subTagBody, + subTagArgs, + extraData, + subTagPermissionMatchParams, + tagFnCallsObj, + ); return rendered.content!; }, });