src: allow -- value form for option arguments#62948
Open
maruthang wants to merge 1 commit intonodejs:mainfrom
Open
src: allow -- value form for option arguments#62948maruthang wants to merge 1 commit intonodejs:mainfrom
-- value form for option arguments#62948maruthang wants to merge 1 commit intonodejs:mainfrom
Conversation
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 <[email protected]>
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The CLI option parser rejected any value beginning with
-whenconsuming the argument for a value-taking option such as
--eval, including the conventional--end-of-options marker.As a result
node -pe -- -0failed 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 readingthe value for a value-taking option: pop the
--and consume thefollowing argv element verbatim. Bare
node -pe -0continues toerror so short-flag stacking and parsing of legitimate options
after
-eare 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.