Skip to content

Commit

Permalink
fix(node/child_process): properly normalize stdio for 'spawnSync' (#2…
Browse files Browse the repository at this point in the history
…1103)

Closes #20782
  • Loading branch information
bartlomieju authored Nov 10, 2023
1 parent 9010b8d commit 612b7df
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
14 changes: 14 additions & 0 deletions cli/tests/unit_node/child_process_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -707,3 +707,17 @@ Deno.test(function spawnSyncUndefinedValueInEnvVar() {
assertEquals(ret.status, 0);
assertEquals(ret.stdout.toString("utf-8").trim(), "BAZ");
});

Deno.test(function spawnSyncStdioUndefined() {
const ret = spawnSync(
`"${Deno.execPath()}" eval "console.log('hello');console.error('world')"`,
{
stdio: [undefined, undefined, undefined],
shell: true,
},
);

assertEquals(ret.status, 0);
assertEquals(ret.stdout.toString("utf-8").trim(), "hello");
assertEquals(ret.stderr.toString("utf-8").trim(), "world");
});
11 changes: 8 additions & 3 deletions ext/node/polyfills/internal/child_process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,12 @@ export function spawnSync(
maxBuffer,
windowsVerbatimArguments = false,
} = options;
const normalizedStdio = normalizeStdioOption(stdio);
const [
_stdin_ = "pipe", // TODO(bartlomieju): use this?
stdout_ = "pipe",
stderr_ = "pipe",
_channel, // TODO(kt3k): handle this correctly
] = normalizeStdioOption(stdio);
[command, args] = buildCommand(command, args ?? [], shell);

const result: SpawnSyncResult = {};
Expand All @@ -844,8 +849,8 @@ export function spawnSync(
args,
cwd,
env: mapValues(env, (value) => value.toString()),
stdout: toDenoStdio(normalizedStdio[1]),
stderr: toDenoStdio(normalizedStdio[2]),
stdout: toDenoStdio(stdout_),
stderr: toDenoStdio(stderr_),
uid,
gid,
windowsRawArguments: windowsVerbatimArguments,
Expand Down

0 comments on commit 612b7df

Please sign in to comment.