From b377cad1e6f3f197afb8d4c798ff1ad2b04f8454 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Wed, 3 Jul 2024 04:50:08 -0300 Subject: [PATCH] fix reporter trying to JSON.stringify regex --- src/debug/runReporter.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/debug/runReporter.ts b/src/debug/runReporter.ts index 33ef2e97b..e0aaf1ff3 100644 --- a/src/debug/runReporter.ts +++ b/src/debug/runReporter.ts @@ -107,6 +107,14 @@ async function runReporter() { parsedArgs = args[0].$$vencordProps.slice(1); } + function stringifyCodeFilter(code: string | RegExp | Webpack.CodeFilter) { + if (Array.isArray(code)) { + return `[${code.map(arg => arg instanceof RegExp ? String(arg) : JSON.stringify(arg)).join(", ")}]`; + } + + return code instanceof RegExp ? String(code) : JSON.stringify(code); + } + // if parsedArgs is the same as args, it means vencordProps of the filter was not available (like in normal filter functions), // so log the filter function instead if ( @@ -129,7 +137,7 @@ async function runReporter() { regexStr = String(matcher); } - logMessage += `(${JSON.stringify(code)}, ${regexStr})`; + logMessage += `(${stringifyCodeFilter(code)}, ${regexStr})`; } else if (searchType === "mapMangledModule") { const [code, mappers] = parsedArgs; @@ -142,13 +150,16 @@ async function runReporter() { const filterName = filter.$$vencordProps[0]; parsedFilter = `${filterName}(${filter.$$vencordProps.slice(1).map((arg: any) => arg instanceof RegExp ? String(arg) : JSON.stringify(arg)).join(", ")})`; } else { - parsedFilter = String(filter).slice(0, 147) + "..."; + parsedFilter = String(filter); + if (parsedFilter.length > 150) { + parsedFilter = parsedFilter.slice(0, 147) + "..."; + } } return [key, parsedFilter]; }); - logMessage += `(${JSON.stringify(code)}, {\n${parsedFailedMappers.map(([key, parsedFilter]) => `\t${key}: ${parsedFilter}`).join(",\n")}\n})`; + logMessage += `(${stringifyCodeFilter(code)}, {\n${parsedFailedMappers.map(([key, parsedFilter]) => `\t${key}: ${parsedFilter}`).join(",\n")}\n})`; } else { logMessage += `(${filterName.length ? `${filterName}(` : ""}${parsedArgs.map(arg => arg instanceof RegExp ? String(arg) : JSON.stringify(arg)).join(", ")})${filterName.length ? ")" : ""}`; }