Skip to content
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

src: fix NODE_OPTIONS parsing bug #22529

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2922,7 +2922,8 @@ void Init(std::vector<std::string>* argv,
index = node_options.find(' ', index + 1);
if (index - prev_index == 1) continue;

const std::string option = node_options.substr(prev_index + 1, index);
const std::string option = node_options.substr(
prev_index + 1, index - prev_index - 1);
if (!option.empty())
env_argv.emplace_back(std::move(option));
} while (index != std::string::npos);
Expand Down
7 changes: 6 additions & 1 deletion test/parallel/test-cli-node-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
process.chdir(tmpdir.path);

expect(`-r ${require.resolve('../fixtures/printA.js')}`, 'A\nB\n');
const printA = require.resolve('../fixtures/printA.js');
expect(`-r ${printA}`, 'A\nB\n');
expect(`-r ${printA} -r ${printA}`, 'A\nB\n');
expect('--no-deprecation', 'B\n');
expect('--no-warnings', 'B\n');
expect('--trace-warnings', 'B\n');
Expand All @@ -29,6 +31,9 @@ expect('--v8-pool-size=10', 'B\n');
expect('--trace-event-categories node', 'B\n');
// eslint-disable-next-line no-template-curly-in-string
expect('--trace-event-file-pattern {pid}-${rotation}.trace_events', 'B\n');
// eslint-disable-next-line no-template-curly-in-string
expect('--trace-event-file-pattern {pid}-${rotation}.trace_events ' +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible we could avoid hard-coding all of these options somehow with 22490 or would that require too much node options metadata to know what (if any) arguments to pass for each?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would work for a number of options (mostly the simple boolean ones), but there are quite a few that change output in some way…

'--trace-event-categories node.async_hooks', 'B\n');

if (!common.isWindows) {
expect('--perf-basic-prof', 'B\n');
Expand Down