From 90204d38fc07d40b1e42de33f4f6670f9ff07731 Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Wed, 31 Aug 2016 13:54:45 -0700 Subject: [PATCH] etcdctl: fix quoted string handling in txn and watch Fixes #6315 --- etcdctl/ctlv3/command/util.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) 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) {