Skip to content

Commit

Permalink
feature(label): tolerate backslash in the label name (#1595) (#2083)
Browse files Browse the repository at this point in the history
Signed-off-by: Shafreeck Sea <shafreeck@gmail.com>
  • Loading branch information
sre-bot committed Jan 7, 2020
1 parent 330c108 commit 488afe4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions server/util.go
Expand Up @@ -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 consists of alphanumeric characters, '-', '_', '.' or '/',
// and must start and end with an alphanumeric character.
func ValidateLabelString(s string) error {
isValid, _ := regexp.MatchString(matchRule, s)
Expand Down
3 changes: 3 additions & 0 deletions server/util_test.go
Expand Up @@ -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)
Expand Down

0 comments on commit 488afe4

Please sign in to comment.