fix(cli): reject malformed timeout options

This commit is contained in:
Peter Steinberger
2026-05-24 01:03:58 +01:00
parent 96959ec3d7
commit 459cee5315
5 changed files with 50 additions and 12 deletions

View File

@@ -10,6 +10,9 @@ describe("parseTimeoutMs", () => {
expect(parseTimeoutMs(undefined)).toBeUndefined();
expect(parseTimeoutMs("")).toBeUndefined();
expect(parseTimeoutMs("nope")).toBeUndefined();
expect(parseTimeoutMs("10abc")).toBeUndefined();
expect(parseTimeoutMs("1.5")).toBeUndefined();
expect(parseTimeoutMs("0")).toBeUndefined();
});
});
@@ -40,4 +43,12 @@ describe("parseTimeoutMsWithFallback", () => {
expect(() => parseTimeoutMsWithFallback("0", 3000)).toThrow('Received: "0"');
expect(() => parseTimeoutMsWithFallback("-1", 3000)).toThrow('Received: "-1"');
});
it("throws on malformed or unsafe parsed values", () => {
expect(() => parseTimeoutMsWithFallback("10abc", 3000)).toThrow('Received: "10abc"');
expect(() => parseTimeoutMsWithFallback("1.5", 3000)).toThrow('Received: "1.5"');
expect(() => parseTimeoutMsWithFallback(String(Number.MAX_SAFE_INTEGER + 1), 3000)).toThrow(
"Received",
);
});
});