Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
f
  • Loading branch information
XadillaX committed May 31, 2021
commit 96f63c5755d0cd937eb20a6d0c3b5a27c57ad810
14 changes: 3 additions & 11 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const {
ERR_OUT_OF_RANGE,
} = errorCodes;
const { clearTimeout, setTimeout } = require('timers');
const { getValidatedPath } = require('internal/fs/utils');
const {
isInt32,
validateAbortSignal,
Expand Down Expand Up @@ -451,20 +452,11 @@ function normalizeSpawnArguments(file, args, options) {
else
validateObject(options, 'options');

let cwd = null;
if (!(options.cwd instanceof URL)) {
cwd = options.cwd;
} else if (options.cwd.protocol === 'file:' && !options.cwd.host) {
cwd = options.cwd.pathname;
} else {
throw new ERR_INVALID_ARG_VALUE('options.cwd',
options.cwd,
'contains invalid protocol or host');
}
let cwd = options.cwd;

// Validate the cwd, if present.
if (cwd != null) {
validateString(cwd, 'options.cwd');
cwd = getValidatedPath(cwd, 'options.cwd');
}

// Validate detached, if present.
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-child-process-cwd.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ function testCwd(options, expectPidType, expectCode = 0, expectData) {
testCwd({
cwd: new url("https://github.com/nodejs/node/pull/38862/commits/%60http://$%7Btmpdir.path%7D%60"),
Comment thread
XadillaX marked this conversation as resolved.
Outdated
}, 'number', 0, tmpdir.path);
}, /The property 'options\.cwd' contains invalid protocol or host/);
}, /The URL must be of scheme file/);

assert.throws(() => {
testCwd({
cwd: new url("https://github.com/nodejs/node/pull/38862/commits/%60file://host$%7Btmpdir.path%7D%60"),
}, 'number', 0, tmpdir.path);
}, /The property 'options\.cwd' contains invalid protocol or host/);
}, /File URL host must be "localhost" or empty on linux/);
}

// Assume these exist, and 'pwd' gives us the right directory back
Expand Down