From 6cff6df910b2006f4f8b66143b99982655fd59c3 Mon Sep 17 00:00:00 2001 From: disksing Date: Tue, 6 Nov 2018 11:38:58 +0800 Subject: [PATCH] pdctl: fix decode key (#1308) --- tools/pd-ctl/pdctl/command/region_command.go | 22 +++++++++----------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/tools/pd-ctl/pdctl/command/region_command.go b/tools/pd-ctl/pdctl/command/region_command.go index 1a6cfedd357..e30bf484e2b 100644 --- a/tools/pd-ctl/pdctl/command/region_command.go +++ b/tools/pd-ctl/pdctl/command/region_command.go @@ -21,6 +21,7 @@ import ( "net/url" "os/exec" "strconv" + "strings" "github.com/spf13/cobra" ) @@ -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)