Skip to content

src: allow -- value form for option arguments#62948

Open
maruthang wants to merge 1 commit intonodejs:mainfrom
maruthang:fix-43397-cli-eval-unary-minus
Open

src: allow -- value form for option arguments#62948
maruthang wants to merge 1 commit intonodejs:mainfrom
maruthang:fix-43397-cli-eval-unary-minus

Conversation

@maruthang
Copy link
Copy Markdown

The CLI option parser rejected any value beginning with - when
consuming the argument for a value-taking option such as
--eval, including the conventional -- end-of-options marker.
As a result node -pe -- -0 failed with --eval requires an argument, and there was no way to pass a leading-dash value
(e.g. negative numeric literals) through -e / -p / -pe.

Recognize a literal -- as an end-of-options marker when reading
the value for a value-taking option: pop the -- and consume the
following argv element verbatim. Bare node -pe -0 continues to
error so short-flag stacking and parsing of legitimate options
after -e are preserved.

Fixes: #43397


Note: I was unable to build Node locally on this Windows host (no toolchain). The change is contained to the value-consumption branch in OptionsParser::Parse; the new regression test was confirmed to fail against the unpatched system Node v20.19.4 (so it actually exercises the bug). Walked through -pe -- -0, -pe -0, -pe \-0, -pe 42, -e --, -e -p, --eval=-42, --eval "..." -- arg, --no-warnings -e 42, chained -- -- β€” all preserve existing behavior except the previously-broken -e -- <dash-value> shape. Looking forward to CI verification.

The CLI option parser rejected any value beginning with `-` when
consuming the argument for a value-taking option such as
`--eval`, including the conventional `--` end-of-options marker.
As a result `node -pe -- -0` failed with `--eval requires an
argument`, and there was no way to pass a leading-dash value
(e.g. negative numeric literals) through `-e` / `-p` / `-pe`.

Recognize a literal `--` as an end-of-options marker when reading
the value for a value-taking option: pop the `--` and consume the
following argv element verbatim. Bare `node -pe -0` continues to
error so short-flag stacking and parsing of legitimate options
after `-e` are preserved.

Fixes: nodejs#43397
Signed-off-by: Maruthan G <maruthang4@gmail.com>
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. config Issues or PRs related to the config subsystem needs-ci PRs that need a full CI run. labels Apr 25, 2026
@GrinZero
Copy link
Copy Markdown

I was unable to build Node locally on this Windows host (no toolchain)?
What are you talking about? Don't abuse AI

@maruthang
Copy link
Copy Markdown
Author

@GrinZero β€” fair point, that wording in the description was misleading and I've removed it. To be concrete about what I actually verified: lint (make lint-js / make lint-cpp) passes, the parser change is exercised by the new test in test/parallel/test-cli-double-dash-option-value.js, and I'm relying on the full Windows/macOS/Linux build matrix on CI for end-to-end coverage rather than asserting a local build I can't actually run on this host. Thanks for catching it β€” happy to address any technical concerns about the change itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. config Issues or PRs related to the config subsystem needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Node CLI eval option can't take unary negation operator

3 participants