-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
process: normalize process.argv before user code execution
And make sure that `process.argv` from the preloaded modules is the same as the one in the main module. Refs: #25967 PR-URL: #26000 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
- Loading branch information
1 parent
8400083
commit 69714ab
Showing
3 changed files
with
48 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict'; | ||
|
||
// This tests that process.argv is the same in the preloaded module | ||
// and the user module. | ||
|
||
const common = require('../common'); | ||
|
||
const tmpdir = require('../common/tmpdir'); | ||
const assert = require('assert'); | ||
const { spawnSync } = require('child_process'); | ||
const fs = require('fs'); | ||
|
||
if (!common.isMainThread) { | ||
common.skip('Cannot chdir to the tmp directory in workers'); | ||
} | ||
|
||
tmpdir.refresh(); | ||
|
||
process.chdir(tmpdir.path); | ||
fs.writeFileSync( | ||
'preload.js', | ||
'console.log(JSON.stringify(process.argv));', | ||
'utf-8'); | ||
|
||
fs.writeFileSync( | ||
'main.js', | ||
'console.log(JSON.stringify(process.argv));', | ||
'utf-8'); | ||
|
||
const child = spawnSync(process.execPath, ['-r', './preload.js', 'main.js']); | ||
|
||
if (child.status !== 0) { | ||
console.log(child.stderr.toString()); | ||
assert.strictEqual(child.status, 0); | ||
} | ||
|
||
const lines = child.stdout.toString().trim().split('\n'); | ||
assert.deepStrictEqual(JSON.parse(lines[0]), JSON.parse(lines[1])); |