提交 7ea9a151 编写于 作者: M Mislav Marohnić

[CLI] Fix parsing empty string within arguments

Fixes https://github.com/github/hub/issues/2036
上级 081810c4
......@@ -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
......
......@@ -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")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册