mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-07 21:54:54 +08:00
add regex check for tag name
This commit is contained in:
parent
9f921beb60
commit
025167f115
2 changed files with 6 additions and 15 deletions
|
@ -4,8 +4,8 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/gravitl/netmaker/database"
|
||||
|
@ -192,11 +192,12 @@ func CheckIDSyntax(id string) error {
|
|||
if len(id) < 3 {
|
||||
return errors.New("name should have min 3 characters")
|
||||
}
|
||||
if HasSymbol(id) {
|
||||
return errors.New("symbols are not allowed")
|
||||
reg, err := regexp.Compile("^[a-zA-Z-]+$")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if strings.Contains(id, ".") {
|
||||
return errors.New("dots not allowed")
|
||||
if !reg.MatchString(id) {
|
||||
return errors.New("invalid name. allowed characters are [a-zA-Z-]")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import (
|
|||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
"github.com/c-robinson/iplib"
|
||||
"github.com/gravitl/netmaker/database"
|
||||
|
@ -149,13 +148,4 @@ func IsSlicesEqual(a, b []string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func HasSymbol(str string) bool {
|
||||
for _, letter := range str {
|
||||
if unicode.IsSymbol(letter) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// == private ==
|
||||
|
|
Loading…
Add table
Reference in a new issue