Skip to content

Commit

Permalink
[CLI] Fix parsing empty string within arguments
Browse files Browse the repository at this point in the history
Fixes #2036
  • Loading branch information
mislav committed Feb 13, 2019
1 parent 081810c commit 7ea9a15
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion utils/args_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (p *ArgsParser) Parse(args []string) ([]string, error) {
for i = 0; i < len(args); i++ {
arg = args[i]

if p.HasTerminated || arg == "-" {
if p.HasTerminated || len(arg) == 0 || arg == "-" {
} else if arg == "--" {
if !p.HasTerminated {
p.HasTerminated = true
Expand Down
8 changes: 8 additions & 0 deletions utils/args_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ func TestArgsParser_UnknownFlag(t *testing.T) {
equal(t, true, p.Bool("--yes"))
}

func TestArgsParser_BlankArgs(t *testing.T) {
p := NewArgsParser()
rest, err := p.Parse([]string{"", ""})
equal(t, nil, err)
equal(t, []string{"", ""}, rest)
equal(t, []int{0, 1}, p.PositionalIndices)
}

func TestArgsParser_Values(t *testing.T) {
p := NewArgsParser()
p.RegisterValue("--origin", "-o")
Expand Down

0 comments on commit 7ea9a15

Please sign in to comment.