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

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
J
Java Code Geeks
量子位
腾讯CDC
C
Check Point Blog
小众软件
小众软件
IT之家
IT之家
I
InfoQ
Hugging Face - Blog
Hugging Face - Blog
Stack Overflow Blog
Stack Overflow Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
GbyAI
GbyAI
Apple Machine Learning Research
Apple Machine Learning Research
大猫的无限游戏
大猫的无限游戏
博客园_首页
S
SegmentFault 最新的问题
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
aimingoo的专栏
aimingoo的专栏
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Google DeepMind News
Google DeepMind News
T
Tailwind CSS Blog
Martin Fowler
Martin Fowler

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: harden telegram html fallback text (#81764) · opencl...
alexph-dev · 2026-05-15 · via Recent Commits to openclaw:main

@@ -165,6 +165,11 @@ const AUTO_LINKED_ANCHOR_PATTERN = /<a\s+href="https?:\/\/([^"]+)"[^>]*>\1<\/a>/

165165

const HTML_TAG_PATTERN = /(<\/?)([a-zA-Z][a-zA-Z0-9-]*)\b[^>]*?>/gi;

166166

const HTML_MODE_TAG_PATTERN = /^<(\/?)([a-zA-Z][a-zA-Z0-9-]*)([^<>]*)>$/;

167167

const ESCAPED_HTML_TAG_PATTERN = /&lt;(\/?)([a-zA-Z][a-zA-Z0-9-]*)(.*?)&gt;/g;

168+

const TELEGRAM_HTML_ANCHOR_PATTERN =

169+

/<a\b[^>]*\bhref\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))[^>]*>([\s\S]*?)<\/a\s*>/gi;

170+

const TELEGRAM_HTML_BREAK_PATTERN = /<br\s*\/?>/gi;

171+

const TELEGRAM_HTML_ENTITY_PATTERN = /&(#x[0-9A-Fa-f]+|#\d+|amp|lt|gt|quot|apos);/g;

172+

const TELEGRAM_HTML_TAG_PATTERN = /<[^>]*>/g;

168173

const TELEGRAM_SIMPLE_HTML_TAGS = new Set([

169174

"b",

170175

"strong",

@@ -274,6 +279,88 @@ function escapeUnsupportedTelegramHtml(text: string): string {

274279

return result;

275280

}

276281282+

function decodeTelegramHtmlEntity(entity: string, fallback: string): string {

283+

if (entity.startsWith("#x") || entity.startsWith("#X")) {

284+

const codePoint = Number.parseInt(entity.slice(2), 16);

285+

return Number.isInteger(codePoint) && codePoint >= 0 && codePoint <= 0x10ffff

286+

? String.fromCodePoint(codePoint)

287+

: fallback;

288+

}

289+

if (entity.startsWith("#")) {

290+

const codePoint = Number.parseInt(entity.slice(1), 10);

291+

return Number.isInteger(codePoint) && codePoint >= 0 && codePoint <= 0x10ffff

292+

? String.fromCodePoint(codePoint)

293+

: fallback;

294+

}

295+

switch (entity) {

296+

case "amp":

297+

return "&";

298+

case "lt":

299+

return "<";

300+

case "gt":

301+

return ">";

302+

case "quot":

303+

return '"';

304+

case "apos":

305+

return "'";

306+

default:

307+

return fallback;

308+

}

309+

}

310+311+

function decodeTelegramHtmlEntities(text: string): string {

312+

return text.replace(TELEGRAM_HTML_ENTITY_PATTERN, (match, entity: string) =>

313+

decodeTelegramHtmlEntity(entity, match),

314+

);

315+

}

316+317+

function stripTelegramHtmlForPlainText(html: string): string {

318+

return decodeTelegramHtmlEntities(

319+

html.replace(TELEGRAM_HTML_BREAK_PATTERN, "\n").replace(TELEGRAM_HTML_TAG_PATTERN, ""),

320+

);

321+

}

322+323+

function encodePlainTextForTelegramHtmlStrip(text: string): string {

324+

return text.replace(/[&<>]/g, (char) => {

325+

switch (char) {

326+

case "&":

327+

return "&amp;";

328+

case "<":

329+

return "&lt;";

330+

case ">":

331+

return "&gt;";

332+

default:

333+

return char;

334+

}

335+

});

336+

}

337+338+

export function telegramHtmlToPlainTextFallback(html: string): string {

339+

TELEGRAM_HTML_ANCHOR_PATTERN.lastIndex = 0;

340+

const withPlainLinks = html.replace(

341+

TELEGRAM_HTML_ANCHOR_PATTERN,

342+

(

343+

_match: string,

344+

doubleQuotedHref: string | undefined,

345+

singleQuotedHref: string | undefined,

346+

unquotedHref: string | undefined,

347+

labelHtml: string,

348+

) => {

349+

const href = decodeTelegramHtmlEntities(

350+

doubleQuotedHref ?? singleQuotedHref ?? unquotedHref ?? "",

351+

).trim();

352+

const label = stripTelegramHtmlForPlainText(labelHtml).trim();

353+

if (!href) {

354+

return encodePlainTextForTelegramHtmlStrip(label);

355+

}

356+

return encodePlainTextForTelegramHtmlStrip(

357+

!label || label === href ? href : `${label} (${href})`,

358+

);

359+

},

360+

);

361+

return stripTelegramHtmlForPlainText(withPlainLinks);

362+

}

363+277364

function promoteEscapedSupportedTelegramTags(text: string, openTags: string[]): string {

278365

ESCAPED_HTML_TAG_PATTERN.lastIndex = 0;

279366

return text.replace(