mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
fix: extend regex for template version name (#6876)
This commit is contained in:
@ -12,6 +12,7 @@ var (
|
||||
UsernameValidRegex = regexp.MustCompile("^[a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*$")
|
||||
usernameReplace = regexp.MustCompile("[^a-zA-Z0-9-]*")
|
||||
|
||||
templateVersionName = regexp.MustCompile(`^[a-zA-Z0-9]+(?:[_.-]{1}[a-zA-Z0-9]+)*$`)
|
||||
templateDisplayName = regexp.MustCompile(`^[^\s](.*[^\s])?$`)
|
||||
)
|
||||
|
||||
@ -52,6 +53,18 @@ func NameValid(str string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// TemplateVersionNameValid returns whether the input string is a valid template version name.
|
||||
func TemplateVersionNameValid(str string) error {
|
||||
if len(str) > 64 {
|
||||
return xerrors.New("must be <= 64 characters")
|
||||
}
|
||||
matched := templateVersionName.MatchString(str)
|
||||
if !matched {
|
||||
return xerrors.New("must be alphanumeric with underscores and dots")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// TemplateDisplayNameValid returns whether the input string is a valid template display name.
|
||||
func TemplateDisplayNameValid(str string) error {
|
||||
if len(str) == 0 {
|
||||
|
Reference in New Issue
Block a user