-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
"--" after "-e <script>" means end-of-options #10651
Conversation
child.exec(nodejs + ' --eval "console.log(process.argv[1])" -- -arg1', | ||
function(status, stdout, stderr) { | ||
assert.strictEqual(stdout, '-arg1\n'); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One suggestion: Could you add tests for more arguments after --
, too?
'-arg1 arg2 --arg3', | ||
'--', | ||
].forEach(function(args) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove this blank line.
function(status, stdout, stderr) { | ||
assert.strictEqual(stdout, args+'\n'); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this one.
].forEach(function(args) { | ||
|
||
child.exec(nodejs + | ||
' --eval "console.log(process.argv.slice(1).join(\' \'))" -- ' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you do this string concatenation in a separate variable, this can be formatted in a much more readable fashion.
' --eval "console.log(process.argv.slice(1).join(\' \'))" -- ' + | ||
args, | ||
function(status, stdout, stderr) { | ||
assert.strictEqual(stdout, args+'\n'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space before and after +
. Does make lint
complain about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed it does :-) Will make sure to run that next time.
child.exec(nodejs + | ||
' --eval "console.log(process.argv.slice(1).join(\' \'))" -- ' + | ||
args, | ||
function(status, stdout, stderr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you wrap the callback in common.mustCall()
, and add assertions for status
(which should probably be renamed) and stderr
.
To be clear, |
Thats right |
@@ -3690,6 +3690,10 @@ static void ParseArgs(int* argc, | |||
} else if (strcmp(arg, "--expose-internals") == 0 || | |||
strcmp(arg, "--expose_internals") == 0) { | |||
// consumed in js | |||
} else if (strcmp(arg, "--") == 0 && eval_string != nullptr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this patch also work with -p
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, The variable "eval_string" is used by both -e and -p
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did... the linter error with no output?
@jBarz could you trying running |
Sorry, more linter errors fixed. Passes now |
'--', | ||
].forEach(function(args) { | ||
const evalopt = ' --eval "console.log(process.argv.slice(1).join(\' \'))"'; | ||
child.exec(nodejs + evalopt + ' -- ' + args, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I meant by my earlier comment about readability is that you can do this:
const cmd = `${nodejs}${evalopt} -- ${args}`;
child.exec(cmd, common.mustCall(function(err, stdout, stderr) {
...
});
It gets rid of that awkward looking indented function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is certainly more readable. Will do
While I see the need the use of the |
I'm not sure how that is less hackish when it uses the same number of characters and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One comment: I would update the description to include how things work with an arg of arg2
in addition to what you currently describe with -arg1
, to show how you are making things more consistent.
Also, I'm not sure if a non -
prefixed arg case already exists in the unit tests, its a bit hard to see from diffs, but if it doesn't exist, it should.
FWIW, the behaviour implemented by this PR is how I would have assumed it worked already. Is this semver-major, or minor, or patch? I could call it semver-patch, since I think the existing behaviour doesn't accord with how I would assume node works. On the other hand, I'm not sure the existing docs cover this behaviour... and @jBarz I just realized this PR doesn't update the docs or the node usage message, shouldn't it? It would be possible for existing code to rely on the current behaviour, though, making this an incompatible semver-major change... or it could be possible to describe this just as a semver-minor, since now we have the capability of passing /cc @gibfahn re: our conversation about what is or is not "API", and thus, an "API change" according to semver. |
assert.strictEqual(stderr, ''); | ||
assert.strictEqual(err, null); | ||
})); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that this is also supposed to work with -p
, including that in the test also would be ideal.
Also, given that this is not supposed to work outside of using -p
and -e
, a test verifying that --
fails when those are not used would be good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by "fails" and "not work"? --
should continue to work as it does currently in absence of -p
and -e
:
% node args.js -- --help
[ '/home/sam/.nvm/versions/node/v7.2.0/bin/node',
'/home/sam/w/core/node/args.js',
'--',
'--help' ]
% node -- args.js --help
[ '/home/sam/.nvm/versions/node/v7.2.0/bin/node',
'/home/sam/w/core/node/args.js',
'--help' ]
% cat args.js
console.log(process.argv)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean that node -- aargs.js
should fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Except that this is a bug:
core/node (master $% u=) % node -- --help
Usage: node [options] [ -e script | script.js ] [arguments]
node debug script.js [arguments]
...
The --
should have stopped the options processing, I would have expected to see something like
core/node (master $% u=) % node -- nexist
module.js:472
throw err;
^
Error: Cannot find module '/home/sam/w/core/node/nexist'
Except with a file name of --help
!
Is it out of scope to fix this bug, too, in this PR @jBarz? Should I report this as a bug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I take that back, you're correct. Using the --
shouldn't fail. I was misreading the PR ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would still like to see the tests expanded to cover the -p
option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before this PR:
"--" is treated as an unknown node option. Hence it is always passed on to v8.
After this PR:
"--" is treated as the end-of-options delimiter if and only if "--eval script" has been used prior to this option. Otherwise, treat it the same as before
I can change it to do what @sam-github says it must do:
"--" is treated as the end-of-options delimiter for all situations
Since node also uses a script name to indicate end-of-options, I would like to clarify what should happen in this case?
node --nodeopt1 script.js arg1 -- arg2
Should "--" be passed into the script or ignored?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
passed in, so that the script.js can use it to indicate the end of its options:
node --some-node-option script.js --some-script-option -- --not-a-script-option
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will commit some additional changes and tests as @jasnell mentioned above. Thanks for the feedback!
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 <[email protected]> Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
Thanks! Landed in 0a9f360. I'll set a |
@bnoordhuis sorry, totally missed your post while landing. I assume it will come out green anyways. |
I think this can be closed given that it’s landed now |
Thanks, forgot to close it. CI came out green 👍 |
@MylesBorins would it be possible to back-port this to v4.x ? |
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 <[email protected]> Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
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: nodejs#10651 Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
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: nodejs#10651 Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
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 Backport-PR-URL: #11013 Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
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 Backport-PR-URL: #11013 Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
This LTS release comes with 126 commits. This includes 40 which are test related, 32 which are doc related, 12 which are build / tool related and 4 commits which are updates to dependencies. Notable Changes: * build: - support for building mips64el (nanxiongchao) #10991 * cluster: - disconnect() now returns a reference to the disconnected worker. (Sean Villars) #10019 * crypto: - ability to select cert store at runtime (Adam Majer) #8334 - Use system CAs instead of using bundled ones (Adam Majer) #8334 - The `Decipher` methods `setAuthTag()` and `setAAD` now return `this`. (Kirill Fomichev) #9398 - adding support for OPENSSL_CONF again (Sam Roberts) #11006 - make LazyTransform compabile with Streams1 (Matteo Collina) #12380 * deps: - upgrade libuv to 1.11.0 (cjihrig) #11094 - upgrade libuv to 1.10.2 (cjihrig) #10717 - upgrade libuv to 1.10.1 (cjihrig) #9647 - upgrade libuv to 1.10.0 (cjihrig) #9267 * dns: - Implemented `{ttl: true}` for `resolve4()` and `resolve6()` (Ben Noordhuis) #9296 * process: - add NODE_NO_WARNINGS environment variable (cjihrig) #10842 * readline: - add option to stop duplicates in history (Danny Nemer) #2982 * src: - support "--" after "-e" as end-of-options (John Barboza) #10651 * tls: - new tls.TLSSocket() supports sec ctx options (Sam Roberts) #11005 - Allow obvious key/passphrase combinations. (Sam Roberts) #10294 PR-URL: #13059
This LTS release comes with 126 commits. This includes 40 which are test related, 32 which are doc related, 12 which are build / tool related and 4 commits which are updates to dependencies. Notable Changes: * build: - support for building mips64el (nanxiongchao) #10991 * cluster: - disconnect() now returns a reference to the disconnected worker. (Sean Villars) #10019 * crypto: - ability to select cert store at runtime (Adam Majer) #8334 - Use system CAs instead of using bundled ones (Adam Majer) #8334 - The `Decipher` methods `setAuthTag()` and `setAAD` now return `this`. (Kirill Fomichev) #9398 - adding support for OPENSSL_CONF again (Sam Roberts) #11006 - make LazyTransform compabile with Streams1 (Matteo Collina) #12380 * deps: - upgrade libuv to 1.11.0 (cjihrig) #11094 - upgrade libuv to 1.10.2 (cjihrig) #10717 - upgrade libuv to 1.10.1 (cjihrig) #9647 - upgrade libuv to 1.10.0 (cjihrig) #9267 * dns: - Implemented `{ttl: true}` for `resolve4()` and `resolve6()` (Ben Noordhuis) #9296 * process: - add NODE_NO_WARNINGS environment variable (cjihrig) #10842 * readline: - add option to stop duplicates in history (Danny Nemer) #2982 * src: - support "--" after "-e" as end-of-options (John Barboza) #10651 * tls: - new tls.TLSSocket() supports sec ctx options (Sam Roberts) #11005 - Allow obvious key/passphrase combinations. (Sam Roberts) #10294 PR-URL: #13059
This LTS release comes with 126 commits. This includes 40 which are test related, 32 which are doc related, 12 which are build / tool related and 4 commits which are updates to dependencies. Notable Changes: * build: - support for building mips64el (nanxiongchao) nodejs/node#10991 * cluster: - disconnect() now returns a reference to the disconnected worker. (Sean Villars) nodejs/node#10019 * crypto: - ability to select cert store at runtime (Adam Majer) nodejs/node#8334 - Use system CAs instead of using bundled ones (Adam Majer) nodejs/node#8334 - The `Decipher` methods `setAuthTag()` and `setAAD` now return `this`. (Kirill Fomichev) nodejs/node#9398 - adding support for OPENSSL_CONF again (Sam Roberts) nodejs/node#11006 - make LazyTransform compabile with Streams1 (Matteo Collina) nodejs/node#12380 * deps: - upgrade libuv to 1.11.0 (cjihrig) nodejs/node#11094 - upgrade libuv to 1.10.2 (cjihrig) nodejs/node#10717 - upgrade libuv to 1.10.1 (cjihrig) nodejs/node#9647 - upgrade libuv to 1.10.0 (cjihrig) nodejs/node#9267 * dns: - Implemented `{ttl: true}` for `resolve4()` and `resolve6()` (Ben Noordhuis) nodejs/node#9296 * process: - add NODE_NO_WARNINGS environment variable (cjihrig) nodejs/node#10842 * readline: - add option to stop duplicates in history (Danny Nemer) nodejs/node#2982 * src: - support "--" after "-e" as end-of-options (John Barboza) nodejs/node#10651 * tls: - new tls.TLSSocket() supports sec ctx options (Sam Roberts) nodejs/node#11005 - Allow obvious key/passphrase combinations. (Sam Roberts) nodejs/node#10294 PR-URL: nodejs/node#13059
There is currently no way to pass the first argument to an eval script that starts with a hyphen.
node -e 'console.log(process.argv)' -arg1
[ '/usr/bin/node' ]
node -e 'console.log(process.argv)' -- -arg1
[ '/usr/bin/node' ]
After this fix
node -e 'console.log(process.argv)' -- -arg1
[ '/usr/bin/node', '-arg1' ]
Checklist
make -j4 test
(UNIX)Affected core subsystem(s)