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 a5f91ab

Browse filesBrowse files
src: throw when -c and -e are used simultaneously
The -c flag ("check script syntax") and -e flag ("evaluate given code") have contradictory meanings. Make them mutually exclusive by throwing when both of them are provided. Fixes: #11680 PR-URL: #11689 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
1 parent 3209a8e commit a5f91ab
Copy full SHA for a5f91ab

File tree

Expand file treeCollapse file tree

2 files changed

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

2 files changed

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

‎src/node.cc‎

Copy file name to clipboardExpand all lines: src/node.cc
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3816,6 +3816,12 @@ static void ParseArgs(int* argc,
38163816
}
38173817
#endif
38183818

3819+
if (eval_string != nullptr && syntax_check_only) {
3820+
fprintf(stderr,
3821+
"%s: either --check or --eval can be used, not both\n", argv[0]);
3822+
exit(9);
3823+
}
3824+
38193825
// Copy remaining arguments.
38203826
const unsigned int args_left = nargs - index;
38213827
memcpy(new_argv + new_argc, argv + index, args_left * sizeof(*argv));
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-cli-syntax.js
+16-1Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ syntaxArgs.forEach(function(args) {
9999
assert.strictEqual(c.status, 0, 'code === ' + c.status);
100100
});
101101

102-
// should should throw if code piped from stdin with --check has bad syntax
102+
// should throw if code piped from stdin with --check has bad syntax
103103
// loop each possible option, `-c` or `--check`
104104
syntaxArgs.forEach(function(args) {
105105
const stdin = 'var foo bar;';
@@ -117,3 +117,18 @@ syntaxArgs.forEach(function(args) {
117117

118118
assert.strictEqual(c.status, 1, 'code === ' + c.status);
119119
});
120+
121+
// should throw if -c and -e flags are both passed
122+
['-c', '--check'].forEach(function(checkFlag) {
123+
['-e', '--eval'].forEach(function(evalFlag) {
124+
const args = [checkFlag, evalFlag, 'foo'];
125+
const c = spawnSync(node, args, {encoding: 'utf8'});
126+
127+
assert.strictEqual(
128+
c.stderr,
129+
`${node}: either --check or --eval can be used, not both\n`
130+
);
131+
132+
assert.strictEqual(c.status, 9, 'code === ' + c.status);
133+
});
134+
});

0 commit comments

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