Repository navigation
util: do not treat a dash in a short option group as the terminator - #67228
yohannesjoya wants to merge 1 commit into
Conversation
parseArgs() expands a short option group such as -a-b into -a, -- and -b. The expanded -- was then handled as the options terminator, so -b became a positional, an option-terminator token was reported although the user never passed --, and the index of every following token was off by one. Report the expanded -- as an option named -, like any other unknown short option in a group. Strict mode now throws ERR_PARSE_ARGS_UNKNOWN_OPTION for -a-b and -a-, and token indexes point at the argument they came from. Fixes: nodejs#67226 Signed-off-by: yohannesjoya <yohannesdestagebru10@gmail.com>
|
Welcome to Node.js, and thank you for your first contribution! Before review, please take a moment to read:
Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal. |
shadowspawn
left a comment
There was a problem hiding this comment.
Was broken for this edge case. Bit annoying needing a check for it, but the code and behaviour is reasonable.
LGTM
|
@shadowspawn thanks for the review. This still needs a collaborator to start CI and approve. @aduh95, you reviewed the earlier parseArgs changes; would you mind taking a look when you have time? |
|
Friendly ping: this has two approvals and a green Jenkins CI run (node-test-pull-request/79140). Could a collaborator add |
parseArgs()expands a short option group such as-a-binto-a,--and-bbefore it reads them. The expanded--was then handled as the real options terminator. So-bbecame a positional, the tokens contained anoption-terminatorthe user never passed, and the index of every following token was off by one, which breaks the documentedargs[token.index]contract. In strict mode-a-breported a misleadingERR_PARSE_ARGS_UNEXPECTED_POSITIONALand-a-was accepted silently.This change remembers whether the current argument came from a group expansion. An expanded
--is reported as an option named-, the same way any other unknown short option in a group is reported. Strict mode now throwsERR_PARSE_ARGS_UNKNOWN_OPTIONfor-a-band-a-, and in non-strict mode the tokens point at the argument they came from. A bare--typed by the user is handled as before. This matchesgetopt(3), which reports-a-basinvalid option -- '-'.Fixes: #67226
The three new tests fail on main and pass with this change.
tools/test.pyforparallel/test-parse-args*andmake lint-jspass locally.AI disclosure: I used a coding agent to help find the bug and draft the tests. I reproduced the behavior on v22.20.0 and main, reviewed the change line by line, and ran the tests above locally.