From 5ff083d0c99657dfebd5983ea48f38137e22455c Mon Sep 17 00:00:00 2001 From: Shafreeck Sea Date: Mon, 24 Jun 2019 16:53:10 +0800 Subject: [PATCH 1/2] feature(label): tolerate backslash in the label name Signed-off-by: Shafreeck Sea Closes #1588 --- server/util.go | 4 ++-- server/util_test.go | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/server/util.go b/server/util.go index 9ce968b21ce..75c4dc19d98 100644 --- a/server/util.go +++ b/server/util.go @@ -296,10 +296,10 @@ func InitHTTPClient(svr *Server) error { return nil } -const matchRule = "^[A-Za-z0-9]([-A-Za-z0-9_.]*[A-Za-z0-9])?$" +const matchRule = "^[A-Za-z0-9]([-A-Za-z0-9_./]*[A-Za-z0-9])?$" // ValidateLabelString checks the legality of the label string. -// The valid label consist of alphanumeric characters, '-', '_' or '.', +// The valid label consist of alphanumeric characters, '-', '_', '/' or '.', // and must start and end with an alphanumeric character. func ValidateLabelString(s string) error { isValid, _ := regexp.MatchString(matchRule, s) diff --git a/server/util_test.go b/server/util_test.go index bed4d72045e..fe36e6ce0bd 100644 --- a/server/util_test.go +++ b/server/util_test.go @@ -68,6 +68,9 @@ func (s *testUtilSuite) TestVerifyLabels(c *C) { {"www.pingcap.com", false}, {"h_127.0.0.1", false}, {"a", false}, + {"a/b", false}, + {"ab/", true}, + {"/ab", true}, } for _, t := range tests { c.Assert(ValidateLabelString(t.label) != nil, Equals, t.hasErr) From a4432b08620ed680cd4fd1c3354858487274a3ee Mon Sep 17 00:00:00 2001 From: Shafreeck Sea Date: Mon, 24 Jun 2019 17:05:19 +0800 Subject: [PATCH 2/2] feature(label): refine the comment Signed-off-by: Shafreeck Sea --- server/util.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/util.go b/server/util.go index 75c4dc19d98..414a3d6126a 100644 --- a/server/util.go +++ b/server/util.go @@ -299,7 +299,7 @@ func InitHTTPClient(svr *Server) error { const matchRule = "^[A-Za-z0-9]([-A-Za-z0-9_./]*[A-Za-z0-9])?$" // ValidateLabelString checks the legality of the label string. -// The valid label consist of alphanumeric characters, '-', '_', '/' or '.', +// The valid label consists of alphanumeric characters, '-', '_', '.' or '/', // and must start and end with an alphanumeric character. func ValidateLabelString(s string) error { isValid, _ := regexp.MatchString(matchRule, s)