Skip to content

Commit 446cf6a

Browse files
committed
child_process: refactor string validation in exec and spawn
1 parent 52c7bb1 commit 446cf6a

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

lib/child_process.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,6 @@ function _forkChild(fd, serializationMode) {
186186
}
187187

188188
function normalizeExecArgs(command, options, callback) {
189-
validateString(command, 'command');
190-
validateArgumentNullCheck(command, 'command');
191-
192189
if (typeof options === 'function') {
193190
callback = options;
194191
options = undefined;
@@ -535,12 +532,17 @@ function copyProcessEnvToEnv(env, name, optionEnv) {
535532
}
536533
}
537534

538-
function normalizeSpawnArguments(file, args, options) {
539-
validateString(file, 'file');
540-
validateArgumentNullCheck(file, 'file');
535+
function validateStringParam(param, paramName) {
536+
validateString(param, paramName);
537+
validateArgumentNullCheck(param, paramName);
538+
539+
if (param.length === 0) {
540+
throw new ERR_INVALID_ARG_VALUE(paramName, param, 'cannot be empty');
541+
}
542+
}
541543

542-
if (file.length === 0)
543-
throw new ERR_INVALID_ARG_VALUE('file', file, 'cannot be empty');
544+
function normalizeSpawnArguments(file, args, options) {
545+
validateStringParam(file, 'file');
544546

545547
if (ArrayIsArray(args)) {
546548
args = ArrayPrototypeSlice(args);

0 commit comments

Comments
 (0)