diff --git a/bin/moshpit-name.mjs b/bin/moshpit-name.mjs index fb4aa80..e461a5c 100755 --- a/bin/moshpit-name.mjs +++ b/bin/moshpit-name.mjs @@ -255,7 +255,14 @@ if (sub === "list") { if (rest.includes("-") && !(rest.length === 1 && rest[0] === "-")) { exitInputError('"-" must be the only input when reading from stdin'); } - const input = rest[0] === "-" || !rest.length ? await readStdin() : rest.join("\n"); + let input; + if (rest[0] === "-" || !rest.length) { + const stdin = await readCommandStdin(); + if (stdin.error) exitInputError(stdin.error); + input = stdin.lines.join("\n"); + } else { + input = rest.join("\n"); + } const parsed = parseTldList(input, limit); if (ndjson) { outNdjson(parsed.entries); diff --git a/test/cli.test.mjs b/test/cli.test.mjs index 4ec83b0..18ba847 100644 --- a/test/cli.test.mjs +++ b/test/cli.test.mjs @@ -111,6 +111,18 @@ test("check bounds stdin bytes before emitting NDJSON", () => { assert.deepEqual(JSON.parse(result.stdout), { error: "stdin accepts at most 1 MiB" }); }); +test("list bounds both explicit and implicit stdin", () => { + const input = Array.from({ length: MAX_BULK_TLDS + 1 }, (_, index) => `name${index}.eggs`).join("\n"); + for (const args of [["list", "-", "--json"], ["list", "--json"]]) { + const result = run(args, input); + assert.equal(result.status, 1); + assert.equal(result.stderr, ""); + assert.deepEqual(JSON.parse(result.stdout), { + error: `stdin accepts at most ${MAX_BULK_TLDS} non-empty lines`, + }); + } +}); + test("NDJSON output handles a downstream reader closing the pipe", async () => { const result = await new Promise((resolve, reject) => { const child = spawn(process.execPath, [BIN, "check", ".eggs", "--ndjson"], {