From c5bc6c3d2dd22acb3f982c7849207bb5851d9226 Mon Sep 17 00:00:00 2001 From: mushuiyu886 Date: Mon, 20 Jul 2026 10:09:09 +0800 Subject: [PATCH] fix(duckduckgo): preserve words around highlighted matches (#111460) --- extensions/duckduckgo/src/ddg-client.ts | 4 +++- .../duckduckgo/src/ddg-search-provider.test.ts | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/extensions/duckduckgo/src/ddg-client.ts b/extensions/duckduckgo/src/ddg-client.ts index 497f13e8f642..f5d484c66511 100644 --- a/extensions/duckduckgo/src/ddg-client.ts +++ b/extensions/duckduckgo/src/ddg-client.ts @@ -53,7 +53,9 @@ function decodeHtmlEntities(text: string): string { } function stripHtml(html: string): string { - return html + // DuckDuckGo match highlights can occur inside words, so remove them without adding whitespace. + const withoutMatchHighlights = html.replace(/<\/?b\b[^>]*>/gi, ""); + return withoutMatchHighlights .replace(/<[^>]+>/g, " ") .replace(/\s+/g, " ") .trim(); diff --git a/extensions/duckduckgo/src/ddg-search-provider.test.ts b/extensions/duckduckgo/src/ddg-search-provider.test.ts index 608caefe54f8..53ab34d503d0 100644 --- a/extensions/duckduckgo/src/ddg-search-provider.test.ts +++ b/extensions/duckduckgo/src/ddg-search-provider.test.ts @@ -254,6 +254,21 @@ describe("duckduckgo web search provider", () => { ]); }); + it("keeps inline result markup from splitting words", () => { + const html = ` + Café guide + Find the best café near you. + `; + + expect(ddgClientTesting.parseDuckDuckGoHtml(html)).toEqual([ + { + title: "Café guide", + url: "https://example.com/cafe", + snippet: "Find the best café near you.", + }, + ]); + }); + it("detects bot challenge pages without flagging ordinary result snippets", () => { const challengeHtml = `