From c84d1a0be14801fa1b007f75a57828d7f60092a7 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Tue, 14 Sep 2021 01:45:15 +0300 Subject: [PATCH] tags: validate input types for timeAdd and timeSub --- backend/src/plugins/Tags/TagsPlugin.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/backend/src/plugins/Tags/TagsPlugin.ts b/backend/src/plugins/Tags/TagsPlugin.ts index 1d1c7c0c..c6674189 100644 --- a/backend/src/plugins/Tags/TagsPlugin.ts +++ b/backend/src/plugins/Tags/TagsPlugin.ts @@ -133,6 +133,10 @@ export const TagsPlugin = zeppelinGuildPlugin()({ return Date.now(); } + if (!Number.isNaN(Number(str))) { + return Number(str); // Unix timestamp as a string + } + return moment.tz(str, "YYYY-MM-DD HH:mm:ss", tz).valueOf(); }, @@ -156,6 +160,14 @@ export const TagsPlugin = zeppelinGuildPlugin()({ let reference; let delay; + for (const [i, arg] of args.entries()) { + if (typeof arg === "number") { + args[i] = String(arg); + } else if (typeof arg !== "string") { + args[i] = ""; + } + } + if (args.length >= 2) { // (time, delay) reference = this.parseDateTime(args[0]); @@ -175,6 +187,14 @@ export const TagsPlugin = zeppelinGuildPlugin()({ let reference; let delay; + for (const [i, arg] of args.entries()) { + if (typeof arg === "number") { + args[i] = String(arg); + } else if (typeof arg !== "string") { + args[i] = ""; + } + } + if (args.length >= 2) { // (time, delay) reference = this.parseDateTime(args[0]);