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 non-finite CLI numbers

Ghraven4966e12718d9
diff --git a/bin/utils/validate.ts b/bin/utils/validate.ts
index 2ef83f0c..a5d073fb 100644
--- a/bin/utils/validate.ts
+++ b/bin/utils/validate.ts
@@ -4,7 +4,7 @@ import { normalizeUrl } from './url';
export function validateNumberInput(value: string) {
const parsedValue = Number(value);
- if (isNaN(parsedValue)) {
+ if (!Number.isFinite(parsedValue)) {
throw new InvalidArgumentError('Not a number.');
}
return parsedValue;
diff --git a/dist/cli.js b/dist/cli.js
index 29aea206..1a3d8c33 100644
--- a/dist/cli.js
+++ b/dist/cli.js
@@ -2430,7 +2430,7 @@ const DEFAULT_PAKE_OPTIONS = {
function validateNumberInput(value) {
const parsedValue = Number(value);
- if (isNaN(parsedValue)) {
+ if (!Number.isFinite(parsedValue)) {
throw new InvalidArgumentError('Not a number.');
}
return parsedValue;
diff --git a/tests/unit/cli-options.test.ts b/tests/unit/cli-options.test.ts
index 3262fd4e..8f45ac97 100644
--- a/tests/unit/cli-options.test.ts
+++ b/tests/unit/cli-options.test.ts
@@ -1,5 +1,6 @@
import { describe, expect, it } from 'vitest';
import { getCliProgram } from '../../bin/helpers/cli-program.js';
+import { validateNumberInput } from '../../bin/utils/validate.js';
describe('CLI options', () => {
const program = getCliProgram();
@@ -46,4 +47,10 @@ describe('CLI options', () => {
expect(option?.defaultValue).toBe(false);
expect(option?.hidden).toBe(true);
});
+
+ it('rejects non-finite numeric option values', () => {
+ expect(() => validateNumberInput('Infinity')).toThrow('Not a number.');
+ expect(() => validateNumberInput('-Infinity')).toThrow('Not a number.');
+ expect(validateNumberInput('1200')).toBe(1200);
+ });
});