Spaces:
Build error
Build error
fix: potential unencoded query
Browse files
backend/functions/src/services/brave-search.ts
CHANGED
|
@@ -58,8 +58,13 @@ export class BraveSearchService extends AsyncService {
|
|
| 58 |
extraHeaders['User-Agent'] = this.threadLocal.get('userAgent');
|
| 59 |
}
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
try {
|
| 62 |
-
const r = await this.braveSearchHTTP.webSearch(
|
| 63 |
|
| 64 |
return r.parsed;
|
| 65 |
} catch (err: any) {
|
|
|
|
| 58 |
extraHeaders['User-Agent'] = this.threadLocal.get('userAgent');
|
| 59 |
}
|
| 60 |
|
| 61 |
+
const encoded = { ...query };
|
| 62 |
+
if (encoded.q) {
|
| 63 |
+
encoded.q = (Buffer.from(encoded.q).toString('ascii') === encoded.q) ? encoded.q : encodeURIComponent(encoded.q);
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
try {
|
| 67 |
+
const r = await this.braveSearchHTTP.webSearch(encoded, { headers: extraHeaders as Record<string, string> });
|
| 68 |
|
| 69 |
return r.parsed;
|
| 70 |
} catch (err: any) {
|