Skip to content

Commit

Permalink
fix: improve arg parsing to tolerate = signs in values (for example i…
Browse files Browse the repository at this point in the history
…n urls)
  • Loading branch information
dreadl0ck committed Jun 28, 2023
1 parent 5fdeedc commit c1666e1
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions arguments.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (c *command) parseArguments(args []string) (string, map[string]string, erro
)

argSlice := strings.Split(val, "=")
if len(argSlice) != 2 {
if len(argSlice) < 2 {
return "", argValues, errors.New("invalid argument: " + val)
}

Expand All @@ -199,12 +199,14 @@ func (c *command) parseArguments(args []string) (string, map[string]string, erro
return "", argValues, errors.New("argument label appeared more than once: " + cmdArg.name)
}

if err := validArgType(argSlice[1], cmdArg.argType); err != nil {
return "", argValues, errors.New(ErrInvalidArgumentType.Error() + ": " + err.Error() + ", label=" + cmdArg.name + ", value=" + argSlice[1])
argValue := strings.Join(argSlice[1:], "=")

if err := validArgType(argValue, cmdArg.argType); err != nil {
return "", argValues, errors.New(ErrInvalidArgumentType.Error() + ": " + err.Error() + ", label=" + cmdArg.name + ", value=" + argValue)
}

// temporarily set value on arg
cmdArg.value = argSlice[1]
cmdArg.value = argValue
} else {
return "", argValues, errors.New("invalid argument: " + val)
}
Expand Down Expand Up @@ -391,4 +393,4 @@ func containsArg(args []*commandArg, name string) (*commandArg, bool) {
}
}
return nil, false
}
}

0 comments on commit c1666e1

Please sign in to comment.