mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
fix(duckduckgo): preserve words around highlighted matches (#111460)
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -254,6 +254,21 @@ describe("duckduckgo web search provider", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it("keeps inline result markup from splitting words", () => {
|
||||
const html = `
|
||||
<a class="result__a" href="https://example.com/cafe">Caf<b>é</b> guide</a>
|
||||
<a class="result__snippet">Find the best caf<b>é</b> near you.</a>
|
||||
`;
|
||||
|
||||
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 = `
|
||||
<html>
|
||||
|
||||
Reference in New Issue
Block a user