From ec9342f95a950ac13f57c85ef577e3bbab180e1a Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Sun, 24 Mar 2024 11:25:53 +0530 Subject: [PATCH] fix(ext/node): handle `null` in stdio array (#23048) Fixes https://github.com/denoland/deno/issues/23045 --- ext/node/polyfills/internal/child_process.ts | 11 ++++++++++- tests/unit_node/child_process_test.ts | 13 +++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/ext/node/polyfills/internal/child_process.ts b/ext/node/polyfills/internal/child_process.ts index 5a9212618d..0ca2a958ec 100644 --- a/ext/node/polyfills/internal/child_process.ts +++ b/ext/node/polyfills/internal/child_process.ts @@ -503,11 +503,20 @@ function normalizeStdioOption( if (Array.isArray(stdio)) { // `[0, 1, 2]` is equivalent to `"inherit"` if ( - stdio.length === 3 && stdio[0] === 0 && stdio[1] === 1 && stdio[2] === 2 + stdio.length === 3 && + (stdio[0] === 0 && stdio[1] === 1 && stdio[2] === 2) ) { return ["inherit", "inherit", "inherit"]; } + // `[null, null, null]` is equivalent to `"pipe" + if ( + stdio.length === 3 && + stdio[0] === null || stdio[1] === null || stdio[2] === null + ) { + return ["pipe", "pipe", "pipe"]; + } + // At least 3 stdio must be created to match node while (stdio.length < 3) { ArrayPrototypePush(stdio, undefined); diff --git a/tests/unit_node/child_process_test.ts b/tests/unit_node/child_process_test.ts index 36d9d4345e..6a1d1dbc54 100644 --- a/tests/unit_node/child_process_test.ts +++ b/tests/unit_node/child_process_test.ts @@ -810,3 +810,16 @@ Deno.test(async function spawnCommandNotFoundErrno() { }); await promise; }); + +// https://github.com/denoland/deno/issues/23045 +Deno.test(function spawnCommandNullStdioArray() { + const ret = spawnSync( + `"${Deno.execPath()}" eval "console.log('hello');console.error('world')"`, + { + stdio: [null, null, null], + shell: true, + }, + ); + + assertEquals(ret.status, 0); +});