Skip to content

Commit 2c483b5

Browse files
fix(searxng): avoid duplicating search endpoint
Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
1 parent f826089 commit 2c483b5

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎extensions/searxng/src/searxng-client.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,21 @@ describe("searxng client", () => {
6464
);
6565
});
6666

67+
it("does not duplicate a configured search endpoint", () => {
68+
expect(
69+
testing.buildSearxngSearchUrl({
70+
baseUrl: "https://search.example.com/search",
71+
query: "openclaw",
72+
}),
73+
).toBe("https://search.example.com/search?q=openclaw&format=json");
74+
expect(
75+
testing.buildSearxngSearchUrl({
76+
baseUrl: "https://search.example.com/search/",
77+
query: "openclaw",
78+
}),
79+
).toBe("https://search.example.com/search?q=openclaw&format=json");
80+
});
81+
6782
it("parses SearXNG JSON results and applies the requested count cap", () => {
6883
expect(
6984
testing.parseSearxngResponseText(

‎extensions/searxng/src/searxng-client.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ function buildSearxngSearchUrl(params: {
7878
language?: string;
7979
}): string {
8080
const url = new URL(params.baseUrl);
81-
const pathname = url.pathname.endsWith("/") ? `${url.pathname}search` : `${url.pathname}/search`;
81+
const basePathname = url.pathname.replace(/\/+$/u, "");
82+
const pathname = basePathname.endsWith("/search") ? basePathname : `${basePathname}/search`;
8283
url.pathname = pathname;
8384
url.search = "";
8485
url.searchParams.set("q", params.query);

0 commit comments

Comments
 (0)