From c1666e14cccb30d4a8e910bf153e11409bf4ef83 Mon Sep 17 00:00:00 2001 From: dreadl0ck Date: Wed, 28 Jun 2023 10:00:39 +0200 Subject: [PATCH] fix: improve arg parsing to tolerate = signs in values (for example in urls) --- arguments.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/arguments.go b/arguments.go index a5607ca..cc44292 100644 --- a/arguments.go +++ b/arguments.go @@ -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) } @@ -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) } @@ -391,4 +393,4 @@ func containsArg(args []*commandArg, name string) (*commandArg, bool) { } } return nil, false -} \ No newline at end of file +}