Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/moshcode.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function parseMax(value) {
throw new Error(`moshcode run: --max must be a positive integer, got ${JSON.stringify(value)}`);
}
const max = Number(value);
if (!Number.isInteger(max) || max < 1) {
if (!Number.isSafeInteger(max) || max < 1) {
throw new Error(`moshcode run: --max must be a positive integer, got ${JSON.stringify(value)}`);
}
return max;
Expand Down
4 changes: 2 additions & 2 deletions src/tui.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,11 @@ async function runFile(args) {
const a = args[i];
if (a === "--max" || a === "-n") {
const v = Number(args[++i]);
if (!Number.isInteger(v) || v < 1) { console.log(err(`--max needs a positive integer`)); return; }
if (!Number.isSafeInteger(v) || v < 1) { console.log(err(`--max needs a positive integer`)); return; }
max = v;
} else if (a.startsWith("--max=")) {
const v = Number(a.slice("--max=".length));
if (!Number.isInteger(v) || v < 1) { console.log(err(`--max needs a positive integer`)); return; }
if (!Number.isSafeInteger(v) || v < 1) { console.log(err(`--max needs a positive integer`)); return; }
max = v;
} else if (a === "--dry-run") {
dryRun = true;
Expand Down
2 changes: 1 addition & 1 deletion test/run-options.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ test("run accepts equals-form max option", async () => {
});

test("run rejects non-decimal max values", async () => {
for (const value of ["1e1", "0x2"]) {
for (const value of ["1e1", "0x2", "9007199254740992"]) {
const result = await run([`--max=${value}`, "--dry-run"]);

assert.equal(result.status, 1);
Expand Down
8 changes: 8 additions & 0 deletions test/tui.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ test("TUI /run rejects unknown options before reading a script file", async () =
assert.doesNotMatch(result.stdout, /can't read --dryrun/);
});

test("TUI /run rejects unsafe iteration limits", async () => {
const result = await runTui("/run --max=9007199254740992\n/quit\n");

assert.equal(result.status, 0);
assert.match(result.stdout, /--max needs a positive integer/);
assert.doesNotMatch(result.stdout, /usage: \/run/);
});

test("TUI /run passes positional args through to moshscript argv", () => {
const dir = mkdtempSync(join(tmpdir(), "moshcode-tui-"));
mkdirSync(join(dir, "space dir"));
Expand Down
Loading