mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-03 18:54:06 +00:00
fix(exa): reject non-decimal search counts
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { parseStrictPositiveInteger } from "openclaw/plugin-sdk/number-runtime";
|
||||
import {
|
||||
buildSearchCacheKey,
|
||||
DEFAULT_SEARCH_COUNT,
|
||||
@@ -171,11 +172,11 @@ function isErrorPayload(value: unknown): value is { error: string; message: stri
|
||||
}
|
||||
|
||||
function resolveExaSearchCount(value: unknown, fallback: number): number {
|
||||
const parsed = typeof value === "number" ? value : Number(value);
|
||||
if (!Number.isFinite(parsed)) {
|
||||
const parsed = parseStrictPositiveInteger(value);
|
||||
if (parsed === undefined) {
|
||||
return fallback;
|
||||
}
|
||||
return Math.max(1, Math.min(EXA_MAX_SEARCH_COUNT, Math.floor(parsed)));
|
||||
return Math.min(EXA_MAX_SEARCH_COUNT, parsed);
|
||||
}
|
||||
|
||||
function parseExaContents(
|
||||
|
||||
@@ -184,6 +184,10 @@ describe("exa web search provider", () => {
|
||||
]);
|
||||
expect(testing.resolveExaSearchCount(80, 10)).toBe(80);
|
||||
expect(testing.resolveExaSearchCount(120, 10)).toBe(100);
|
||||
expect(testing.resolveExaSearchCount("+05", 10)).toBe(5);
|
||||
expect(testing.resolveExaSearchCount("0x10", 10)).toBe(10);
|
||||
expect(testing.resolveExaSearchCount("1e2", 10)).toBe(10);
|
||||
expect(testing.resolveExaSearchCount(1.5, 10)).toBe(10);
|
||||
});
|
||||
|
||||
it("returns validation errors for conflicting time filters", async () => {
|
||||
|
||||
Reference in New Issue
Block a user