Skip to content

Commit f5e6e06

Browse files
author
Gio Della-Libera
committed
fix(update): reject blank timeout values
1 parent fc07931 commit f5e6e06

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

src/cli/update-cli/shared.command-runner.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ describe("createGlobalCommandRunner", () => {
5959
expect(parseTimeoutMsOrExit("10abc")).toBeNull();
6060
expect(parseTimeoutMsOrExit("0")).toBeNull();
6161
expect(parseTimeoutMsOrExit("-1")).toBeNull();
62+
expect(parseTimeoutMsOrExit(" ")).toBeNull();
6263

63-
expect(error).toHaveBeenCalledTimes(4);
64+
expect(error).toHaveBeenCalledTimes(5);
6465
expect(error).toHaveBeenCalledWith("--timeout must be a positive integer (seconds)");
65-
expect(exit).toHaveBeenCalledTimes(4);
66+
expect(exit).toHaveBeenCalledTimes(5);
6667
expect(exit).toHaveBeenCalledWith(1);
6768
} finally {
6869
error.mockRestore();

src/cli/update-cli/shared.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ export type UpdateWizardOptions = {
5454
const INVALID_TIMEOUT_ERROR = "--timeout must be a positive integer (seconds)";
5555

5656
export function parseTimeoutMsOrExit(timeout?: string): number | undefined | null {
57-
const trimmed = timeout?.trim();
58-
if (!trimmed) {
57+
if (timeout === undefined) {
5958
return undefined;
6059
}
60+
const trimmed = timeout.trim();
6161
const seconds = Number(trimmed);
6262
if (!/^\d+$/u.test(trimmed) || !Number.isSafeInteger(seconds) || seconds <= 0) {
6363
defaultRuntime.error(INVALID_TIMEOUT_ERROR);

0 commit comments

Comments
 (0)