mirror of
https://github.com/garethgeorge/backrest.git
synced 2025-12-12 08:45:38 +00:00
fix: reserve IDs starting and ending with '__' for internal use
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user