farkhalit opened a new pull request, #434:
URL: https://github.com/apache/commons-cli/pull/434
Repro: `--=/etc/shadow` parsed against an `Options` that holds a single long
option `--config-file`. Both `DefaultParser` and `PosixParser` return a
`CommandLine` with `config-file` set to `/etc/shadow`, and an empty argument
list. Nothing on the command line named that option.
Cause: `getMatchingOptions` strips the hyphens off `--`, leaving an empty
name, and `longOpt.startsWith("")` holds for every entry, so an empty name
matches the entire long option table. `handleLongOptionWithEqual` splits `--=V`
into opt `--` and value `V`, sees one match, and binds. `PosixParser.flatten`
reaches the same list from its own `--` branch. With more than one long option
defined the same token raises `AmbiguousOptionException` naming all of them
rather than rejecting it, and `isLongOption` classifies `-=` as an option, so
`-=` cannot be passed as a value to the option before it.
Fix: an empty name is not a partial name, so return no matches for it. Both
parsers share that one lookup, and `--=V` now reaches `handleUnknownToken` like
any other token that names no option.
What this costs an application is the assumption that a long option is only
set when its name appears in argv. A launcher or wrapper that inspects argv and
refuses, say, `--config-file` sees `--=...` name nothing, while the parser
behind it binds the value anyway.
- [x] Read the [contribution guidelines](CONTRIBUTING.md) for this project.
- [ ] Read the [ASF Generative Tooling
Guidance](https://www.apache.org/legal/generative-tooling.html) if you use
Artificial Intelligence (AI).
- [ ] I used AI to create any part of, or all of, this pull request. Which
AI tool was used to create this pull request, and to what extent did it
contribute?
- [x] Run a successful build using the default
[Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command
line by itself.
- [x] Write unit tests that match behavioral changes, where the tests fail
if the changes to the runtime are not applied. This may not always be possible,
but it is a best practice.
- [x] Write a pull request description that is detailed enough to understand
what the pull request does, how, and why.
- [x] Each commit in the pull request should have a meaningful subject line
and body. Note that a maintainer may squash commits during the merge process.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]