Skip to content

Commit

Permalink
etcdctl: fix quoted string handling in txn and watch
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Romano committed Sep 1, 2016
1 parent a6d22b9 commit 90204d3
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions etcdctl/ctlv3/command/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 90204d3

Please sign in to comment.