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

推荐订阅源

V
V2EX
aimingoo的专栏
aimingoo的专栏
S
SegmentFault 最新的问题
博客园_首页
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
IT之家
IT之家
博客园 - 【当耐特】
月光博客
月光博客
C
Check Point Blog
T
The Blog of Author Tim Ferriss
罗磊的独立博客
博客园 - Franky
MongoDB | Blog
MongoDB | Blog
H
Help Net Security
Microsoft Security Blog
Microsoft Security Blog
B
Blog
阮一峰的网络日志
阮一峰的网络日志
腾讯CDC
美团技术团队
N
Netflix TechBlog - Medium
Stack Overflow Blog
Stack Overflow Blog
Y
Y Combinator Blog
L
LangChain Blog
The Cloudflare 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(duckduckgo): decode & last in decodeHtmlEntities ...
ly-wang19 · 2026-06-24 · via Recent Commits to openclaw:main

File tree

  • extensions/duckduckgo/src

Original file line numberDiff line numberDiff line change

@@ -36,21 +36,49 @@ type DuckDuckGoResult = {

3636

};

3737
3838

function decodeHtmlEntities(text: string): string {

39-

return text

40-

.replace(/&/g, "&")

41-

.replace(/&lt;/g, "<")

42-

.replace(/&gt;/g, ">")

43-

.replace(/&quot;/g, '"')

44-

.replace(/&apos;/g, "'")

45-

.replace(/&#39;/g, "'")

46-

.replace(/&#x27;/g, "'")

47-

.replace(/&#x2F;/g, "/")

48-

.replace(/&nbsp;/g, " ")

49-

.replace(/&ndash;/g, "-")

50-

.replace(/&mdash;/g, "--")

51-

.replace(/&hellip;/g, "...")

52-

.replace(/&#(\d+);/g, (_, code) => String.fromCodePoint(Number(code)))

53-

.replace(/&#x([0-9a-f]+);/gi, (_, code) => String.fromCodePoint(Number.parseInt(code, 16)));

39+

return text.replace(

40+

/&(?:lt|gt|quot|apos|#39|#x27|#x2F|nbsp|ndash|mdash|hellip|amp|#\d+|#x[0-9a-f]+);/gi,

41+

(entity) => {

42+

const normalized = entity.toLowerCase();

43+

if (normalized === "&lt;") {

44+

return "<";

45+

}

46+

if (normalized === "&gt;") {

47+

return ">";

48+

}

49+

if (normalized === "&quot;") {

50+

return '"';

51+

}

52+

if (normalized === "&apos;" || normalized === "&#39;" || normalized === "&#x27;") {

53+

return "'";

54+

}

55+

if (normalized === "&#x2f;") {

56+

return "/";

57+

}

58+

if (normalized === "&nbsp;") {

59+

return " ";

60+

}

61+

if (normalized === "&ndash;") {

62+

return "-";

63+

}

64+

if (normalized === "&mdash;") {

65+

return "--";

66+

}

67+

if (normalized === "&hellip;") {

68+

return "...";

69+

}

70+

if (normalized === "&amp;") {

71+

return "&";

72+

}

73+

if (normalized.startsWith("&#x")) {

74+

return String.fromCodePoint(Number.parseInt(normalized.slice(3, -1), 16));

75+

}

76+

if (normalized.startsWith("&#")) {

77+

return String.fromCodePoint(Number.parseInt(normalized.slice(2, -1), 10));

78+

}

79+

return entity;

80+

},

81+

);

5482

}

5583
5684

function stripHtml(html: string): string {

Original file line numberDiff line numberDiff line change

@@ -186,6 +186,17 @@ describe("duckduckgo web search provider", () => {

186186

);

187187

});

188188
189+

it("does not double-decode escaped entities (decodes &amp; last)", () => {

190+

// A result whose text literally shows "&lt;" arrives double-encoded as

191+

// "&amp;lt;". Decoding &amp; first would re-decode it into "<", corrupting

192+

// the snippet; &amp; must be decoded last.

193+

expect(ddgClientTesting.decodeHtmlEntities("How to escape &amp;lt; in HTML")).toBe(

194+

"How to escape &lt; in HTML",

195+

);

196+

expect(ddgClientTesting.decodeHtmlEntities("a&amp;#39;b")).toBe("a&#39;b");

197+

expect(ddgClientTesting.decodeHtmlEntities("a&#x26;amp;b")).toBe("a&amp;b");

198+

});

199+
189200

it("parses results when href appears before class", () => {

190201

const html = `

191202

<a href="https://duckduckgo.com/l/?uddg=https%3A%2F%2Fexample.com" class="result__a">