Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 978acd1

Browse filesBrowse files
jBarzItalo A. Casas
authored andcommitted
src: support "--" after "-e" as end-of-options
When the double dash "--" appears after "-e <script>" on the command line, it indicates the end of options and the beginning of positional parameters for the script. PR-URL: #10651 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 6687b95 commit 978acd1
Copy full SHA for 978acd1

File tree

Expand file treeCollapse file tree

4 files changed

+61
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+61
-1
lines changed
Open diff view settings
Collapse file

‎doc/api/cli.md‎

Copy file name to clipboardExpand all lines: doc/api/cli.md
+10-1Lines changed: 10 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ To view this documentation as a manual page in your terminal, run `man node`.
1010

1111
## Synopsis
1212

13-
`node [options] [v8 options] [script.js | -e "script"] [arguments]`
13+
`node [options] [v8 options] [script.js | -e "script"] [--] [arguments]`
1414

1515
`node debug [script.js | -e "script" | <host>:<port>] …`
1616

@@ -269,6 +269,15 @@ added: v0.11.15
269269

270270
Specify ICU data load path. (overrides `NODE_ICU_DATA`)
271271

272+
### `--`
273+
<!-- YAML
274+
added: REPLACEME
275+
-->
276+
277+
Indicate the end of node options. Pass the rest of the arguments to the script.
278+
If no script filename or eval/print script is supplied prior to this, then
279+
the next argument will be used as a script filename.
280+
272281
## Environment Variables
273282

274283
### `NODE_DEBUG=module[,…]`
Collapse file

‎doc/node.1‎

Copy file name to clipboardExpand all lines: doc/node.1
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ node \- Server-side JavaScript runtime
3737
.RI [ script.js \ |
3838
.B -e
3939
.RI \&" script \&"]
40+
.B [--]
4041
.RI [ arguments ]
4142
.br
4243
.B node debug
@@ -191,6 +192,13 @@ See \fBSSL_CERT_DIR\fR and \fBSSL_CERT_FILE\fR.
191192
.BR \-\-icu\-data\-dir =\fIfile\fR
192193
Specify ICU data load path. (overrides \fBNODE_ICU_DATA\fR)
193194

195+
.TP
196+
.BR \-\-\fR
197+
Indicate the end of node options. Pass the rest of the arguments to the script.
198+
199+
If no script filename or eval/print script is supplied prior to this, then
200+
the next argument will be used as a script filename.
201+
194202
.SH ENVIRONMENT VARIABLES
195203

196204
.TP
Collapse file

‎src/node.cc‎

Copy file name to clipboardExpand all lines: src/node.cc
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3688,6 +3688,9 @@ static void ParseArgs(int* argc,
36883688
} else if (strcmp(arg, "--expose-internals") == 0 ||
36893689
strcmp(arg, "--expose_internals") == 0) {
36903690
// consumed in js
3691+
} else if (strcmp(arg, "--") == 0) {
3692+
index += 1;
3693+
break;
36913694
} else {
36923695
// V8 option. Pass through as-is.
36933696
new_v8_argv[new_v8_argc] = arg;
Collapse file

‎test/parallel/test-cli-eval.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-cli-eval.js
+40Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ const child = require('child_process');
1212
const path = require('path');
1313
const nodejs = `"${process.execPath}"`;
1414

15+
if (process.argv.length > 2) {
16+
console.log(process.argv.slice(2).join(' '));
17+
process.exit(0);
18+
}
19+
1520
// Assert that nothing is written to stdout.
1621
child.exec(`${nodejs} --eval 42`, common.mustCall((err, stdout, stderr) => {
1722
assert.ifError(err);
@@ -133,3 +138,38 @@ child.exec(`${nodejs} --use-strict -p process.execArgv`,
133138
assert.strictEqual(proc.stderr, '');
134139
assert.strictEqual(proc.stdout, 'start\nbeforeExit\nexit\n');
135140
}
141+
142+
[ '-arg1',
143+
'-arg1 arg2 --arg3',
144+
'--',
145+
'arg1 -- arg2',
146+
].forEach(function(args) {
147+
148+
// Ensure that arguments are successfully passed to eval.
149+
const opt = ' --eval "console.log(process.argv.slice(1).join(\' \'))"';
150+
const cmd = `${nodejs}${opt} -- ${args}`;
151+
child.exec(cmd, common.mustCall(function(err, stdout, stderr) {
152+
assert.strictEqual(stdout, args + '\n');
153+
assert.strictEqual(stderr, '');
154+
assert.strictEqual(err, null);
155+
}));
156+
157+
// Ensure that arguments are successfully passed to print.
158+
const popt = ' --print "process.argv.slice(1).join(\' \')"';
159+
const pcmd = `${nodejs}${popt} -- ${args}`;
160+
child.exec(pcmd, common.mustCall(function(err, stdout, stderr) {
161+
assert.strictEqual(stdout, args + '\n');
162+
assert.strictEqual(stderr, '');
163+
assert.strictEqual(err, null);
164+
}));
165+
166+
// Ensure that arguments are successfully passed to a script.
167+
// The first argument after '--' should be interpreted as a script
168+
// filename.
169+
const filecmd = `${nodejs} -- ${__filename} ${args}`;
170+
child.exec(filecmd, common.mustCall(function(err, stdout, stderr) {
171+
assert.strictEqual(stdout, args + '\n');
172+
assert.strictEqual(stderr, '');
173+
assert.strictEqual(err, null);
174+
}));
175+
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.