forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
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: nodejs#25967
- Loading branch information
1 parent
8465016
commit 487f9ca
Showing
4 changed files
with
45 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 @@ | ||
console.log(JSON.stringify(process.argv)); |
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])); |