Skip to content

Commit 590b56c

Browse files
committed
fix(run): require decimal max values
1 parent dfcb8c1 commit 590b56c

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

bin/moshcode.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ function readScript(arg) {
4444

4545
function parseMax(value) {
4646
if (value === undefined) throw new Error("moshcode run: --max requires a positive integer");
47+
if (!/^\d+$/.test(String(value))) {
48+
throw new Error(`moshcode run: --max must be a positive integer, got ${JSON.stringify(value)}`);
49+
}
4750
const max = Number(value);
4851
if (!Number.isInteger(max) || max < 1) {
4952
throw new Error(`moshcode run: --max must be a positive integer, got ${JSON.stringify(value)}`);

test/run-options.test.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ test("run accepts equals-form max option", async () => {
8282
assert.match(result.stdout, /1 loop\(s\)/);
8383
});
8484

85+
test("run rejects non-decimal max values", async () => {
86+
for (const value of ["1e1", "0x2"]) {
87+
const result = await run([`--max=${value}`, "--dry-run"]);
88+
89+
assert.equal(result.status, 1);
90+
assert.match(result.stderr, /moshcode run: --max must be a positive integer/);
91+
}
92+
});
93+
8594
test("run() marks the nested moshcode child as nested", async () => {
8695
const dir = mkdtempSync(join(tmpdir(), "moshcode-nested-"));
8796
const child = join(dir, "child.mosh");

0 commit comments

Comments
 (0)