Skip to content

Commit

Permalink
pdctl: fix decode key (tikv#1308)
Browse files Browse the repository at this point in the history
  • Loading branch information
disksing committed Nov 8, 2018
1 parent 2ea58d1 commit 6cff6df
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions tools/pd-ctl/pdctl/command/region_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"net/url"
"os/exec"
"strconv"
"strings"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -260,19 +261,16 @@ func decodeKey(text string) (string, error) {
continue
}
n := r.Next(1)
if len(n) == 0 {
return "", io.EOF
}
// See: https://golang.org/ref/spec#Rune_literals
if idx := strings.IndexByte(`abfnrtv\'"`, n[0]); idx != -1 {
buf = append(buf, []byte("\a\b\f\n\r\t\v\\'\"")[idx])
continue
}

switch n[0] {
case '"':
buf = append(buf, '"')
case '\'':
buf = append(buf, '\'')
case '\\':
buf = append(buf, '\\')
case 'n':
buf = append(buf, '\n')
case 't':
buf = append(buf, '\t')
case 'r':
buf = append(buf, '\r')
case 'x':
fmt.Sscanf(string(r.Next(2)), "%02x", &c)
buf = append(buf, c)
Expand Down

0 comments on commit 6cff6df

Please sign in to comment.