Fix panic on empty-string value for list options - #11347
Open
nikolauspschuetz wants to merge 1 commit into
Open
Conversation
getListValues checked arg[0] == '-' without a length guard, so an empty string argument panicked with index out of range. This is reachable from the CLI for any list-valued option, e.g. dolt log --not "", dolt log -t "", or dolt diff --include-cols "", which aborted with a runtime panic instead of accepting the empty value. Check for the empty string before indexing. Adds a regression test that panics before this change and passes after.
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.
What
getListValues(go/libraries/utils/argparser/parser.go) checkedarg[0] == '-'without a length guard, so an empty-string value for any list-valued option panicked:This is reachable from the CLI for any option built with
SupportsStringList(i.e.AllowMultipleOptions), e.g.:Each aborts with a runtime panic instead of accepting the empty value.
Fix
Test for the empty string before indexing
arg[0]:An empty value is now collected like any other non-flag argument, and a following option (
-l "" -f) still terminates the list.Testing
Added
TestArgParserListEmptyValue, which panics before this change and passes after. The fullargparserpackage tests,go vet, andgofmtare clean.