Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 36.4k
child_process: spawn ignores options in case args is undefined#24913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| 'use strict'; | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is already a test for this behaviour, could you expand it instead of adding another test file? See Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sam-github Nit or requirement to land? Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather it lands with these changes. Particularly with API consistency.
| ||
| // This test confirms that `undefined`, `null`, and `[]` | ||
| // can be used as a placeholder for the second argument (`args`) of `spawn()`. | ||
| // Previously, there was a bug where using `undefined` for the second argument | ||
| // caused the third argument (`options`) to be ignored. | ||
| // See https://github.com/nodejs/node/issues/24912. | ||
| const assert = require('assert'); | ||
| const { spawn } = require('child_process'); | ||
| const common = require('../common'); | ||
| const tmpdir = require('../common/tmpdir'); | ||
| const command = common.isWindows ? 'cd' : 'pwd'; | ||
| const options = { cwd: tmpdir.path }; | ||
| if (common.isWindows) { | ||
| // This test is not the case for Windows based systems | ||
| // unless the `shell` options equals to `true` | ||
| options.shell = true; | ||
| } | ||
| const testCases = [ | ||
| undefined, | ||
| null, | ||
| [], | ||
| ]; | ||
| const expectedResult = tmpdir.path.trim().toLowerCase(); | ||
| (async () => { | ||
| const results = await Promise.all( | ||
| testCases.map((testCase) => { | ||
| return new Promise((resolve) => { | ||
| const subprocess = spawn(command, testCase, options); | ||
| let accumulatedData = Buffer.alloc(0); | ||
| subprocess.stdout.on('data', common.mustCall((data) => { | ||
| accumulatedData = Buffer.concat([accumulatedData, data]); | ||
| })); | ||
| subprocess.stdout.on('end', () => { | ||
| resolve(accumulatedData.toString().trim().toLowerCase()); | ||
| }); | ||
| }); | ||
| }) | ||
| ); | ||
| assert.deepStrictEqual([...new Set(results)], [expectedResult]); | ||
| })(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| 'use strict'; | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added same test for | ||
| // This test confirms that `undefined`, `null`, and `[]` can be used | ||
| // as a placeholder for the second argument (`args`) of `spawnSync()`. | ||
| // Previously, there was a bug where using `undefined` for the second argument | ||
| // caused the third argument (`options`) to be ignored. | ||
| // See https://github.com/nodejs/node/issues/24912. | ||
| const assert = require('assert'); | ||
| const { spawnSync } = require('child_process'); | ||
| const common = require('../common'); | ||
| const tmpdir = require('../common/tmpdir'); | ||
| const command = common.isWindows ? 'cd' : 'pwd'; | ||
| const options = { cwd: tmpdir.path }; | ||
| if (common.isWindows) { | ||
| // This test is not the case for Windows based systems | ||
| // unless the `shell` options equals to `true` | ||
| options.shell = true; | ||
| } | ||
| const testCases = [ | ||
| undefined, | ||
| null, | ||
| [], | ||
| ]; | ||
| const expectedResult = tmpdir.path.trim().toLowerCase(); | ||
| const results = testCases.map((testCase) => { | ||
| const { stdout, stderr } = spawnSync( | ||
| command, | ||
| testCase, | ||
| options | ||
| ); | ||
| assert.deepStrictEqual(stderr, Buffer.alloc(0)); | ||
| return stdout.toString().trim().toLowerCase(); | ||
| }); | ||
| assert.deepStrictEqual([...new Set(results)], [expectedResult]); | ||
Uh oh!
There was an error while loading. Please reload this page.