diff --git a/etcdctl/ctlv3/command/util.go b/etcdctl/ctlv3/command/util.go index 57464510e39b..af8d3c1b1189 100644 --- a/etcdctl/ctlv3/command/util.go +++ b/etcdctl/ctlv3/command/util.go @@ -48,8 +48,23 @@ func addHexPrefix(s string) string { } func argify(s string) []string { - r := regexp.MustCompile("'.+'|\".+\"|\\S+") - return r.FindAllString(s, -1) + r := regexp.MustCompile(`"(\\.|[^"])*"|'[^']*'|\w+`) + args := r.FindAllString(s, -1) + for i := range args { + if len(args[i]) == 0 { + continue + } + if args[i][0] == '\'' { + // 'single-quoted string' + args[i] = args[i][1 : len(args)-1] + } else if args[i][0] == '"' { + // "double quoted string" + if _, err := fmt.Sscanf(args[i], "%q", &args[i]); err != nil { + ExitWithError(ExitInvalidInput, err) + } + } + } + return args } func commandCtx(cmd *cobra.Command) (context.Context, context.CancelFunc) {