tailcfg: use strings.CutPrefix for CheckTag; add test

Updates #cleanup

Signed-off-by: Andrew Dunham <andrew@du.nham.ca>
Change-Id: I42eddc7547a6dd50c4d5b2a9fc88a19aac9767aa
This commit is contained in:
Andrew Dunham
2024-05-31 17:01:05 -04:00
parent 0a5bd63d32
commit 36d0ac6f8e
2 changed files with 27 additions and 2 deletions
+3 -2
View File
@@ -609,10 +609,11 @@ func isAlpha(b byte) bool {
//
// We might relax these rules later.
func CheckTag(tag string) error {
if !strings.HasPrefix(tag, "tag:") {
var ok bool
tag, ok = strings.CutPrefix(tag, "tag:")
if !ok {
return errors.New("tags must start with 'tag:'")
}
tag = tag[4:]
if tag == "" {
return errors.New("tag names must not be empty")
}