惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

大猫的无限游戏
大猫的无限游戏
月光博客
月光博客
博客园 - Franky
博客园 - 三生石上(FineUI控件)
爱范儿
爱范儿
博客园 - 司徒正美
博客园 - 叶小钗
Apple Machine Learning Research
Apple Machine Learning Research
美团技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
B
Blog RSS Feed
阮一峰的网络日志
阮一峰的网络日志
宝玉的分享
宝玉的分享
V
Visual Studio Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
IT之家
IT之家
博客园_首页
S
SegmentFault 最新的问题
A
About on SuperTechFans
Blog — PlanetScale
Blog — PlanetScale
GbyAI
GbyAI
H
Help Net Security
MongoDB | Blog
MongoDB | Blog

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(discord): escape component custom id delimiters · ope...
steipete · 2026-05-29 · via Recent Commits to openclaw:main

@@ -2,17 +2,55 @@ import { parseCustomId, type ComponentParserResult } from "./internal/discord.js

2233

export const DISCORD_COMPONENT_CUSTOM_ID_KEY = "occomp";

44

export const DISCORD_MODAL_CUSTOM_ID_KEY = "ocmodal";

5+

const ENCODED_CUSTOM_ID_VERSION = "1";

6+7+

function encodeCustomIdValue(value: string): string {

8+

return value.replace(/%/g, "%25").replace(/;/g, "%3B");

9+

}

10+11+

function needsCustomIdEncoding(value: string): boolean {

12+

return /[%;]/.test(value);

13+

}

14+15+

function decodeCustomIdValue(value: string): string {

16+

return value.replace(/%(25|3B)/gi, (match) => (match.toLowerCase() === "%25" ? "%" : ";"));

17+

}

18+19+

function decodeParsedCustomIdData(

20+

data: ComponentParserResult["data"],

21+

): ComponentParserResult["data"] {

22+

if (data.e !== ENCODED_CUSTOM_ID_VERSION) {

23+

return data;

24+

}

25+

return Object.fromEntries(

26+

Object.entries(data).map(([key, value]) => [

27+

key,

28+

typeof value === "string" ? decodeCustomIdValue(value) : value,

29+

]),

30+

) as ComponentParserResult["data"];

31+

}

532633

export function buildDiscordComponentCustomId(params: {

734

componentId: string;

835

modalId?: string;

936

}): string {

10-

const base = `${DISCORD_COMPONENT_CUSTOM_ID_KEY}:cid=${params.componentId}`;

11-

return params.modalId ? `${base};mid=${params.modalId}` : base;

37+

const encoded =

38+

needsCustomIdEncoding(params.componentId) || needsCustomIdEncoding(params.modalId ?? "");

39+

const componentId = encoded ? encodeCustomIdValue(params.componentId) : params.componentId;

40+

const base = encoded

41+

? `${DISCORD_COMPONENT_CUSTOM_ID_KEY}:e=${ENCODED_CUSTOM_ID_VERSION};cid=${componentId}`

42+

: `${DISCORD_COMPONENT_CUSTOM_ID_KEY}:cid=${componentId}`;

43+

const modalId = params.modalId;

44+

if (!modalId) {

45+

return base;

46+

}

47+

return `${base};mid=${encoded ? encodeCustomIdValue(modalId) : modalId}`;

1248

}

13491450

export function buildDiscordModalCustomId(modalId: string): string {

15-

return `${DISCORD_MODAL_CUSTOM_ID_KEY}:mid=${modalId}`;

51+

return needsCustomIdEncoding(modalId)

52+

? `${DISCORD_MODAL_CUSTOM_ID_KEY}:e=${ENCODED_CUSTOM_ID_VERSION};mid=${encodeCustomIdValue(modalId)}`

53+

: `${DISCORD_MODAL_CUSTOM_ID_KEY}:mid=${modalId}`;

1654

}

17551856

export function parseDiscordComponentCustomId(

@@ -22,11 +60,12 @@ export function parseDiscordComponentCustomId(

2260

if (parsed.key !== DISCORD_COMPONENT_CUSTOM_ID_KEY) {

2361

return null;

2462

}

25-

const componentId = parsed.data.cid;

63+

const data = decodeParsedCustomIdData(parsed.data);

64+

const componentId = data.cid;

2665

if (typeof componentId !== "string" || !componentId.trim()) {

2766

return null;

2867

}

29-

const modalId = parsed.data.mid;

68+

const modalId = data.mid;

3069

return {

3170

componentId,

3271

modalId: typeof modalId === "string" && modalId.trim() ? modalId : undefined,

@@ -38,7 +77,8 @@ export function parseDiscordModalCustomId(id: string): string | null {

3877

if (parsed.key !== DISCORD_MODAL_CUSTOM_ID_KEY) {

3978

return null;

4079

}

41-

const modalId = parsed.data.mid;

80+

const data = decodeParsedCustomIdData(parsed.data);

81+

const modalId = data.mid;

4282

if (typeof modalId !== "string" || !modalId.trim()) {

4383

return null;

4484

}

@@ -57,7 +97,7 @@ export function parseDiscordComponentCustomIdForInteraction(id: string): Compone

5797

if (parsed.key !== DISCORD_COMPONENT_CUSTOM_ID_KEY) {

5898

return parsed;

5999

}

60-

return { key: "*", data: parsed.data };

100+

return { key: "*", data: decodeParsedCustomIdData(parsed.data) };

61101

}

6210263103

export function parseDiscordModalCustomIdForInteraction(id: string): ComponentParserResult {

@@ -68,5 +108,5 @@ export function parseDiscordModalCustomIdForInteraction(id: string): ComponentPa

68108

if (parsed.key !== DISCORD_MODAL_CUSTOM_ID_KEY) {

69109

return parsed;

70110

}

71-

return { key: "*", data: parsed.data };

111+

return { key: "*", data: decodeParsedCustomIdData(parsed.data) };

72112

}