From e95f96f77a86666a15ea1b2a88fea16e9e1ada31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E8=82=96=E7=84=B6?= Date: Sat, 28 Feb 2026 20:32:18 +0800 Subject: [PATCH] fix(discord): guard cid decode to avoid URIError --- src/discord/monitor/agent-components.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/discord/monitor/agent-components.ts b/src/discord/monitor/agent-components.ts index 22f4fc90562..0f5a871f64e 100644 --- a/src/discord/monitor/agent-components.ts +++ b/src/discord/monitor/agent-components.ts @@ -423,9 +423,26 @@ function parseAgentComponentData(data: ComponentData): { : (data as Record).componentId) ?? (data as Record).componentId; + const decodeSafe = (value: string): string => { + // `cid` values may be raw (not URI-encoded). Guard against malformed % sequences. + // Only attempt decoding when it looks like it contains percent-encoding. + if (!value.includes("%")) { + return value; + } + // If it has a % but not a valid %XX sequence, skip decode. + if (!/%[0-9A-Fa-f]{2}/.test(value)) { + return value; + } + try { + return decodeURIComponent(value); + } catch { + return value; + } + }; + const componentId = typeof raw === "string" - ? decodeURIComponent(raw) + ? decodeSafe(raw) : typeof raw === "number" ? String(raw) : null;