fix: potential unencoded query

This commit is contained in:
Yanlong Wang 2024-05-17 09:15:37 +08:00
parent ed9e9f43cf
commit 2941be6096
No known key found for this signature in database
GPG Key ID: C0A623C0BADF9F37

View File

@ -58,8 +58,13 @@ export class BraveSearchService extends AsyncService {
extraHeaders['User-Agent'] = this.threadLocal.get('userAgent');
}
const encoded = { ...query };
if (encoded.q) {
encoded.q = (Buffer.from(encoded.q).toString('ascii') === encoded.q) ? encoded.q : encodeURIComponent(encoded.q);
}
try {
const r = await this.braveSearchHTTP.webSearch(query, { headers: extraHeaders as Record<string, string> });
const r = await this.braveSearchHTTP.webSearch(encoded, { headers: extraHeaders as Record<string, string> });
return r.parsed;
} catch (err: any) {