Skip to content

armgit / Pake

Public Imported from GitHub
0

Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.

fix: reject blank numeric CLI values

Ghraven7eb7bd9fb144
diff --git a/bin/utils/validate.ts b/bin/utils/validate.ts
index b85153c1..3ed66d68 100644
--- a/bin/utils/validate.ts
+++ b/bin/utils/validate.ts
@@ -3,6 +3,9 @@ import { InvalidArgumentError } from 'commander';
import { normalizeUrl } from './url';
export function validateNumberInput(value: string) {
+ if (value.trim() === '') {
+ throw new InvalidArgumentError('Not a number.');
+ }
const parsedValue = Number(value);
if (!Number.isFinite(parsedValue)) {
throw new InvalidArgumentError('Not a number.');
diff --git a/dist/cli.js b/dist/cli.js
index 7c43f616..9337e411 100644
--- a/dist/cli.js
+++ b/dist/cli.js
@@ -2540,6 +2540,9 @@ const DEFAULT_PAKE_OPTIONS = {
};
function validateNumberInput(value) {
+ if (value.trim() === '') {
+ throw new InvalidArgumentError('Not a number.');
+ }
const parsedValue = Number(value);
if (!Number.isFinite(parsedValue)) {
throw new InvalidArgumentError('Not a number.');
diff --git a/tests/unit/cli-options.test.ts b/tests/unit/cli-options.test.ts
index dc79b4b3..85969b66 100644
--- a/tests/unit/cli-options.test.ts
+++ b/tests/unit/cli-options.test.ts
@@ -64,6 +64,11 @@ describe('CLI options', () => {
expect(validateNumberInput('1200')).toBe(1200);
});
+ it('rejects blank numeric option values', () => {
+ expect(() => validateNumberInput('')).toThrow('Not a number.');
+ expect(() => validateNumberInput(' ')).toThrow('Not a number.');
+ });
+
it('rejects negative numeric option values', () => {
expect(() => validateNumberInput('-100')).toThrow('Must not be negative.');
expect(validateNumberInput('0')).toBe(0);