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
9 changes: 8 additions & 1 deletion bin/moshpit-name.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions test/cli.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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"], {
Expand Down
Loading