| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -146,6 +146,10 @@ exec('"my script.cmd" a b', (err, stdout, stderr) => { | |||
| 146 | 146 | <!-- YAML | |
| 147 | 147 | added: v0.1.90 | |
| 148 | 148 | changes: | |
| 149 | + - version: REPLACEME | ||
| 150 | + pr-url: https://github.com/nodejs/node/pull/38862 | ||
| 151 | + description: The `cwd` option can be a WHATWG `URL` object using | ||
| 152 | + `file:` protocol. | ||
| 149 | 153 | - version: v15.4.0 | |
| 150 | 154 | pr-url: https://github.com/nodejs/node/pull/36308 | |
| 151 | 155 | description: AbortSignal support was added. | |
@@ -156,7 +160,7 @@ changes: | |||
| 156 | 160 | ||
| 157 | 161 | * `command` {string} The command to run, with space-separated arguments. | |
| 158 | 162 | * `options` {Object} | |
| 159 | - * `cwd` {string} Current working directory of the child process. | ||
| 163 | + * `cwd` {string|URL} Current working directory of the child process. | ||
| 160 | 164 | **Default:** `process.cwd()`. | |
| 161 | 165 | * `env` {Object} Environment key-value pairs. **Default:** `process.env`. | |
| 162 | 166 | * `encoding` {string} **Default:** `'utf8'` | |
@@ -271,6 +275,10 @@ controller.abort(); | |||
| 271 | 275 | <!-- YAML | |
| 272 | 276 | added: v0.1.91 | |
| 273 | 277 | changes: | |
| 278 | + - version: REPLACEME | ||
| 279 | + pr-url: https://github.com/nodejs/node/pull/38862 | ||
| 280 | + description: The `cwd` option can be a WHATWG `URL` object using | ||
| 281 | + `file:` protocol. | ||
| 274 | 282 | - version: v15.4.0 | |
| 275 | 283 | pr-url: https://github.com/nodejs/node/pull/36308 | |
| 276 | 284 | description: AbortSignal support was added. | |
@@ -282,7 +290,7 @@ changes: | |||
| 282 | 290 | * `file` {string} The name or path of the executable file to run. | |
| 283 | 291 | * `args` {string[]} List of string arguments. | |
| 284 | 292 | * `options` {Object} | |
| 285 | - * `cwd` {string} Current working directory of the child process. | ||
| 293 | + * `cwd` {string|URL} Current working directory of the child process. | ||
| 286 | 294 | * `env` {Object} Environment key-value pairs. **Default:** `process.env`. | |
| 287 | 295 | * `encoding` {string} **Default:** `'utf8'` | |
| 288 | 296 | * `timeout` {number} **Default:** `0` | |
@@ -374,6 +382,10 @@ controller.abort(); | |||
| 374 | 382 | <!-- YAML | |
| 375 | 383 | added: v0.5.0 | |
| 376 | 384 | changes: | |
| 385 | + - version: REPLACEME | ||
| 386 | + pr-url: https://github.com/nodejs/node/pull/38862 | ||
| 387 | + description: The `cwd` option can be a WHATWG `URL` object using | ||
| 388 | + `file:` protocol. | ||
| 377 | 389 | - version: v15.13.0 | |
| 378 | 390 | pr-url: https://github.com/nodejs/node/pull/37256 | |
| 379 | 391 | description: timeout was added. | |
@@ -399,7 +411,7 @@ changes: | |||
| 399 | 411 | * `modulePath` {string} The module to run in the child. | |
| 400 | 412 | * `args` {string[]} List of string arguments. | |
| 401 | 413 | * `options` {Object} | |
| 402 | - * `cwd` {string} Current working directory of the child process. | ||
| 414 | + * `cwd` {string|URL} Current working directory of the child process. | ||
| 403 | 415 | * `detached` {boolean} Prepare child to run independently of its parent | |
| 404 | 416 | process. Specific behavior depends on the platform, see | |
| 405 | 417 | [`options.detached`][]). | |
@@ -483,6 +495,10 @@ if (process.argv[2] === 'child') { | |||
| 483 | 495 | <!-- YAML | |
| 484 | 496 | added: v0.1.90 | |
| 485 | 497 | changes: | |
| 498 | + - version: REPLACEME | ||
| 499 | + pr-url: https://github.com/nodejs/node/pull/38862 | ||
| 500 | + description: The `cwd` option can be a WHATWG `URL` object using | ||
| 501 | + `file:` protocol. | ||
| 486 | 502 | - version: v15.13.0 | |
| 487 | 503 | pr-url: https://github.com/nodejs/node/pull/37256 | |
| 488 | 504 | description: timeout was added. | |
@@ -511,7 +527,7 @@ changes: | |||
| 511 | 527 | * `command` {string} The command to run. | |
| 512 | 528 | * `args` {string[]} List of string arguments. | |
| 513 | 529 | * `options` {Object} | |
| 514 | - * `cwd` {string} Current working directory of the child process. | ||
| 530 | + * `cwd` {string|URL} Current working directory of the child process. | ||
| 515 | 531 | * `env` {Object} Environment key-value pairs. **Default:** `process.env`. | |
| 516 | 532 | * `argv0` {string} Explicitly set the value of `argv[0]` sent to the child | |
| 517 | 533 | process. This will be set to `command` if not specified. | |
@@ -839,6 +855,10 @@ configuration at startup. | |||
| 839 | 855 | <!-- YAML | |
| 840 | 856 | added: v0.11.12 | |
| 841 | 857 | changes: | |
| 858 | + - version: REPLACEME | ||
| 859 | + pr-url: https://github.com/nodejs/node/pull/38862 | ||
| 860 | + description: The `cwd` option can be a WHATWG `URL` object using | ||
| 861 | + `file:` protocol. | ||
| 842 | 862 | - version: v10.10.0 | |
| 843 | 863 | pr-url: https://github.com/nodejs/node/pull/22409 | |
| 844 | 864 | description: The `input` option can now be any `TypedArray` or a | |
@@ -859,7 +879,7 @@ changes: | |||
| 859 | 879 | * `file` {string} The name or path of the executable file to run. | |
| 860 | 880 | * `args` {string[]} List of string arguments. | |
| 861 | 881 | * `options` {Object} | |
| 862 | - * `cwd` {string} Current working directory of the child process. | ||
| 882 | + * `cwd` {string|URL} Current working directory of the child process. | ||
| 863 | 883 | * `input` {string|Buffer|TypedArray|DataView} The value which will be passed | |
| 864 | 884 | as stdin to the spawned process. Supplying this value will override | |
| 865 | 885 | `stdio[0]`. | |
@@ -908,6 +928,10 @@ arbitrary command execution.** | |||
| 908 | 928 | <!-- YAML | |
| 909 | 929 | added: v0.11.12 | |
| 910 | 930 | changes: | |
| 931 | + - version: REPLACEME | ||
| 932 | + pr-url: https://github.com/nodejs/node/pull/38862 | ||
| 933 | + description: The `cwd` option can be a WHATWG `URL` object using | ||
| 934 | + `file:` protocol. | ||
| 911 | 935 | - version: v10.10.0 | |
| 912 | 936 | pr-url: https://github.com/nodejs/node/pull/22409 | |
| 913 | 937 | description: The `input` option can now be any `TypedArray` or a | |
@@ -922,7 +946,7 @@ changes: | |||
| 922 | 946 | ||
| 923 | 947 | * `command` {string} The command to run. | |
| 924 | 948 | * `options` {Object} | |
| 925 | - * `cwd` {string} Current working directory of the child process. | ||
| 949 | + * `cwd` {string|URL} Current working directory of the child process. | ||
| 926 | 950 | * `input` {string|Buffer|TypedArray|DataView} The value which will be passed | |
| 927 | 951 | as stdin to the spawned process. Supplying this value will override | |
| 928 | 952 | `stdio[0]`. | |
@@ -968,6 +992,10 @@ metacharacters may be used to trigger arbitrary command execution.** | |||
| 968 | 992 | <!-- YAML | |
| 969 | 993 | added: v0.11.12 | |
| 970 | 994 | changes: | |
| 995 | + - version: REPLACEME | ||
| 996 | + pr-url: https://github.com/nodejs/node/pull/38862 | ||
| 997 | + description: The `cwd` option can be a WHATWG `URL` object using | ||
| 998 | + `file:` protocol. | ||
| 971 | 999 | - version: v10.10.0 | |
| 972 | 1000 | pr-url: https://github.com/nodejs/node/pull/22409 | |
| 973 | 1001 | description: The `input` option can now be any `TypedArray` or a | |
@@ -991,7 +1019,7 @@ changes: | |||
| 991 | 1019 | * `command` {string} The command to run. | |
| 992 | 1020 | * `args` {string[]} List of string arguments. | |
| 993 | 1021 | * `options` {Object} | |
| 994 | - * `cwd` {string} Current working directory of the child process. | ||
| 1022 | + * `cwd` {string|URL} Current working directory of the child process. | ||
| 995 | 1023 | * `input` {string|Buffer|TypedArray|DataView} The value which will be passed | |
| 996 | 1024 | as stdin to the spawned process. Supplying this value will override | |
| 997 | 1025 | `stdio[0]`. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -71,6 +71,7 @@ const { | |||
| 71 | 71 | ERR_OUT_OF_RANGE, | |
| 72 | 72 | } = errorCodes; | |
| 73 | 73 | const { clearTimeout, setTimeout } = require('timers'); | |
| 74 | + const { getValidatedPath } = require('internal/fs/utils'); | ||
| 74 | 75 | const { | |
| 75 | 76 | isInt32, | |
| 76 | 77 | validateAbortSignal, | |
@@ -450,9 +451,11 @@ function normalizeSpawnArguments(file, args, options) { | |||
| 450 | 451 | else | |
| 451 | 452 | validateObject(options, 'options'); | |
| 452 | 453 | ||
| 454 | + let cwd = options.cwd; | ||
| 455 | + | ||
| 453 | 456 | // Validate the cwd, if present. | |
| 454 | - if (options.cwd != null) { | ||
| 455 | - validateString(options.cwd, 'options.cwd'); | ||
| 457 | + if (cwd != null) { | ||
| 458 | + cwd = getValidatedPath(cwd, 'options.cwd'); | ||
| 456 | 459 | } | |
| 457 | 460 | ||
| 458 | 461 | // Validate detached, if present. | |
@@ -577,11 +580,12 @@ function normalizeSpawnArguments(file, args, options) { | |||
| 577 | 580 | // Make a shallow copy so we don't clobber the user's options object. | |
| 578 | 581 | ...options, | |
| 579 | 582 | args, | |
| 583 | + cwd, | ||
| 580 | 584 | detached: !!options.detached, | |
| 581 | 585 | envPairs, | |
| 582 | 586 | file, | |
| 583 | 587 | windowsHide: !!options.windowsHide, | |
| 584 | - windowsVerbatimArguments: !!windowsVerbatimArguments | ||
| 588 | + windowsVerbatimArguments: !!windowsVerbatimArguments, | ||
| 585 | 589 | }; | |
| 586 | 590 | } | |
| 587 | 591 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,12 +20,14 @@ | |||
| 20 | 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| 21 | 21 | ||
| 22 | 22 | 'use strict'; | |
| 23 | + | ||
| 23 | 24 | const common = require('../common'); | |
| 24 | 25 | const tmpdir = require('../common/tmpdir'); | |
| 25 | 26 | tmpdir.refresh(); | |
| 26 | 27 | ||
| 27 | 28 | const assert = require('assert'); | |
| 28 | 29 | const { spawn } = require('child_process'); | |
| 30 | + const { pathToFileURL, URL } = require('url'); | ||
| 29 | 31 | ||
| 30 | 32 | // Spawns 'pwd' with given options, then test | |
| 31 | 33 | // - whether the child pid is undefined or number, | |
@@ -66,10 +68,27 @@ function testCwd(options, expectPidType, expectCode = 0, expectData) { | |||
| 66 | 68 | })); | |
| 67 | 69 | } | |
| 68 | 70 | ||
| 71 | + { | ||
| 72 | + assert.throws(() => { | ||
| 73 | + testCwd({ | ||
| 74 | + cwd: new URL('http://example.com/'), | ||
| 75 | + }, 'number', 0, tmpdir.path); | ||
| 76 | + }, /The URL must be of scheme file/); | ||
| 77 | + | ||
| 78 | + if (process.platform !== 'win32') { | ||
| 79 | + assert.throws(() => { | ||
| 80 | + testCwd({ | ||
| 81 | + cwd: new URL('file://host/dev/null'), | ||
| 82 | + }, 'number', 0, tmpdir.path); | ||
| 83 | + }, /File URL host must be "localhost" or empty on/); | ||
| 84 | + } | ||
| 85 | + } | ||
| 86 | + | ||
| 69 | 87 | // Assume these exist, and 'pwd' gives us the right directory back | |
| 70 | 88 | testCwd({ cwd: tmpdir.path }, 'number', 0, tmpdir.path); | |
| 71 | 89 | const shouldExistDir = common.isWindows ? process.env.windir : '/dev'; | |
| 72 | 90 | testCwd({ cwd: shouldExistDir }, 'number', 0, shouldExistDir); | |
| 91 | + testCwd({ cwd: pathToFileURL(tmpdir.path) }, 'number', 0, tmpdir.path); | ||
| 73 | 92 | ||
| 74 | 93 | // Spawn() shouldn't try to chdir() to invalid arg, so this should just work | |
| 75 | 94 | testCwd({ cwd: '' }, 'number'); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments