mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-03 14:04:14 +00:00
fix: reject partial numeric runtime values
This commit is contained in:
@@ -480,6 +480,11 @@ describe("argv helpers", () => {
|
||||
argv: ["node", "openclaw", "status", "--timeout", "nope"],
|
||||
expected: undefined,
|
||||
},
|
||||
{
|
||||
name: "partial integer",
|
||||
argv: ["node", "openclaw", "status", "--timeout", "5s"],
|
||||
expected: undefined,
|
||||
},
|
||||
])("parses positive integer flag values: $name", ({ argv, expected }) => {
|
||||
expect(getPositiveIntFlagValue(argv, "--timeout")).toBe(expected);
|
||||
});
|
||||
|
||||
@@ -76,11 +76,12 @@ export function isHelpOrVersionInvocation(argv: string[]): boolean {
|
||||
}
|
||||
|
||||
function parsePositiveInt(value: string): number | undefined {
|
||||
const parsed = Number.parseInt(value, 10);
|
||||
if (Number.isNaN(parsed) || parsed <= 0) {
|
||||
const trimmed = value.trim();
|
||||
if (!/^\d+$/.test(trimmed)) {
|
||||
return undefined;
|
||||
}
|
||||
return parsed;
|
||||
const parsed = Number(trimmed);
|
||||
return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : undefined;
|
||||
}
|
||||
|
||||
export function hasFlag(argv: string[], name: string): boolean {
|
||||
|
||||
Reference in New Issue
Block a user