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 malformed zoom values

Ghravencb113484c89a
diff --git a/bin/helpers/cli-program.ts b/bin/helpers/cli-program.ts
index 4780e0f6..5460a8ba 100644
--- a/bin/helpers/cli-program.ts
+++ b/bin/helpers/cli-program.ts
@@ -212,8 +212,8 @@ ${green('|_| \\__,_|_|\\_\\___| can turn any webpage into a desktop app with
new Option('--zoom <number>', 'Initial page zoom level (50-200)')
.default(DEFAULT.zoom)
.argParser((value) => {
- const zoom = parseInt(value);
- if (isNaN(zoom) || zoom < 50 || zoom > 200) {
+ const zoom = Number(value);
+ if (!Number.isFinite(zoom) || zoom < 50 || zoom > 200) {
throw new Error('--zoom must be a number between 50 and 200');
}
return zoom;
diff --git a/tests/unit/cli-options.test.ts b/tests/unit/cli-options.test.ts
index 3262fd4e..0f588dd8 100644
--- a/tests/unit/cli-options.test.ts
+++ b/tests/unit/cli-options.test.ts
@@ -46,4 +46,14 @@ describe('CLI options', () => {
expect(option?.defaultValue).toBe(false);
expect(option?.hidden).toBe(true);
});
+
+ it('rejects malformed zoom values instead of truncating them', () => {
+ const option = program.options.find((item) => item.long === '--zoom');
+
+ expect(option).toBeDefined();
+ expect(option?.parseArg?.('80', undefined)).toBe(80);
+ expect(() => option?.parseArg?.('80abc', undefined)).toThrow(
+ '--zoom must be a number between 50 and 200',
+ );
+ });
});