Skip to content

Commit 2c5dfef

Browse files
addaleaxtargos
authored andcommitted
src: fix NODE_OPTIONS parsing bug
I, uhm, might have messed up by using a `substr(start, end)` signature when `std::string` actually uses `substr(start, len)`. Fix that. Fixes: #22526 Refs: #22392 PR-URL: #22529 Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent f77bbe8 commit 2c5dfef

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/node.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -2921,7 +2921,8 @@ void Init(std::vector<std::string>* argv,
29212921
index = node_options.find(' ', index + 1);
29222922
if (index - prev_index == 1) continue;
29232923

2924-
const std::string option = node_options.substr(prev_index + 1, index);
2924+
const std::string option = node_options.substr(
2925+
prev_index + 1, index - prev_index - 1);
29252926
if (!option.empty())
29262927
env_argv.emplace_back(std::move(option));
29272928
} while (index != std::string::npos);

test/parallel/test-cli-node-options.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ const tmpdir = require('../common/tmpdir');
1414
tmpdir.refresh();
1515
process.chdir(tmpdir.path);
1616

17-
expect(`-r ${require.resolve('../fixtures/printA.js')}`, 'A\nB\n');
17+
const printA = require.resolve('../fixtures/printA.js');
18+
expect(`-r ${printA}`, 'A\nB\n');
19+
expect(`-r ${printA} -r ${printA}`, 'A\nB\n');
1820
expect('--no-deprecation', 'B\n');
1921
expect('--no-warnings', 'B\n');
2022
expect('--trace-warnings', 'B\n');
@@ -29,6 +31,9 @@ expect('--v8-pool-size=10', 'B\n');
2931
expect('--trace-event-categories node', 'B\n');
3032
// eslint-disable-next-line no-template-curly-in-string
3133
expect('--trace-event-file-pattern {pid}-${rotation}.trace_events', 'B\n');
34+
// eslint-disable-next-line no-template-curly-in-string
35+
expect('--trace-event-file-pattern {pid}-${rotation}.trace_events ' +
36+
'--trace-event-categories node.async_hooks', 'B\n');
3237

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

0 commit comments

Comments
 (0)