mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 03:18:26 +00:00
fix(discord): guard cid decode to avoid URIError
This commit is contained in:
@@ -423,9 +423,26 @@ function parseAgentComponentData(data: ComponentData): {
|
||||
: (data as Record<string, unknown>).componentId) ??
|
||||
(data as Record<string, unknown>).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;
|
||||
|
||||
Reference in New Issue
Block a user