fix: reserve IDs starting and ending with '__' for internal use

This commit is contained in:
garethgeorge
2024-05-18 19:24:05 -07:00
parent fcdf07da6c
commit 711064fb00

View File

@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"regexp"
"strings"
)
var (
@@ -26,6 +27,9 @@ func SanitizeID(id string) string {
// It returns an error if the ID contains invalid characters, is empty, or is too long.
// The maxLen parameter is the maximum length of the ID. If maxLen is 0, the ID length is not checked.
func ValidateID(id string, maxLen int) error {
if strings.HasPrefix(id, "__") && strings.HasSuffix(id, "__") {
return errors.New("IDs starting and ending with '__' are reserved by backrest")
}
if !idRegex.MatchString(id) {
return ErrInvalidChars
}