-
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
- Loading branch information
1 parent
8d6105b
commit 5ea16b0
Showing
3 changed files
with
44 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,34 @@ | ||
'use strict'; | ||
|
||
// This tests that process.argv is the same in the preloaded module | ||
// and the user module. | ||
|
||
require('../common'); | ||
|
||
const tmpdir = require('../common/tmpdir'); | ||
const assert = require('assert'); | ||
const { spawnSync } = require('child_process'); | ||
const fs = require('fs'); | ||
|
||
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])); |