Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in which "fooasdf -o=foo" is incorrectly identified as the subcommand "foo" #93

Merged
merged 2 commits into from Apr 21, 2022

Conversation

kmoe
Copy link
Contributor

@kmoe kmoe commented Apr 21, 2022

Fixes #92

There are a number of ways to fix this. Another approach would be to modify the regex used on line 704 to explicitly exclude cases in which the string ending in the subcommand is itself a flag.

Add a failing test demonstrating that "fooasdf -o=foo" is incorrectly
matched to the subcommand "foo".
When determining the string to use when querying the radix tree for the
longest subcommand, exclude any argument beginning with a "-", since
this is a flag and not a subcommand.

This fixes a bug in which "fooasdf -o=foo" is matched to the subcommand
"foo" due to logic further down on line 704.
@mitchellh
Copy link
Owner

Looks great. Very amusing no one has ever noticed this before. :) Thank you! I think this approach is totally fine (and maybe the best), as long as we have a test and there is no user-facing API change we can always improve the implementation if we find a better approach.

@mitchellh mitchellh merged commit 249ea46 into mitchellh:master Apr 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Subcommand parsing: "fooasdf -o=foo" is incorrectly identified as the subcommand "foo"
2 participants