fix(ext/node): fix timeout param validation in cp.execFile (#22262)

This commit is contained in:
Yoshiya Hinosawa 2024-02-05 14:28:28 +09:00 committed by GitHub
parent 56f58a047e
commit 961fa27c76
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 9 deletions

View File

@ -754,3 +754,20 @@ Deno.test(async function forkIpcKillDoesNotHang() {
await p.promise;
});
Deno.test(async function execFileWithUndefinedTimeout() {
const { promise, resolve, reject } = Promise.withResolvers<void>();
CP.execFile(
"git",
["-v"],
{ timeout: undefined, encoding: "utf8" },
(err) => {
if (err) {
reject(err);
return;
}
resolve();
},
);
await promise;
});

View File

@ -436,15 +436,7 @@ export function execFile(
shell: false,
...options,
};
if (!Number.isInteger(execOptions.timeout) || execOptions.timeout < 0) {
// In Node source, the first argument to error constructor is "timeout" instead of "options.timeout".
// timeout is indeed a member of options object.
throw new ERR_OUT_OF_RANGE(
"timeout",
"an unsigned integer",
execOptions.timeout,
);
}
validateTimeout(execOptions.timeout);
if (execOptions.maxBuffer < 0) {
throw new ERR_OUT_OF_RANGE(
"options.maxBuffer",