File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 (
Original file line number Diff line number Diff 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 ) ;
You can’t perform that action at this time.
0 commit comments