Skip to content

Commit

Permalink
child_process: refactor string validation in exec and spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
puskin94 committed Jan 9, 2025
1 parent 52c7bb1 commit 446cf6a
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,6 @@ function _forkChild(fd, serializationMode) {
}

function normalizeExecArgs(command, options, callback) {
validateString(command, 'command');
validateArgumentNullCheck(command, 'command');

if (typeof options === 'function') {
callback = options;
options = undefined;
Expand Down Expand Up @@ -535,12 +532,17 @@ function copyProcessEnvToEnv(env, name, optionEnv) {
}
}

function normalizeSpawnArguments(file, args, options) {
validateString(file, 'file');
validateArgumentNullCheck(file, 'file');
function validateStringParam(param, paramName) {
validateString(param, paramName);
validateArgumentNullCheck(param, paramName);

if (param.length === 0) {
throw new ERR_INVALID_ARG_VALUE(paramName, param, 'cannot be empty');
}
}

if (file.length === 0)
throw new ERR_INVALID_ARG_VALUE('file', file, 'cannot be empty');
function normalizeSpawnArguments(file, args, options) {
validateStringParam(file, 'file');

if (ArrayIsArray(args)) {
args = ArrayPrototypeSlice(args);
Expand Down

0 comments on commit 446cf6a

Please sign in to comment.