mirror of
https://github.com/garethgeorge/backrest.git
synced 2025-12-12 16:55:39 +00:00
fix: reserve IDs starting and ending with '__' for internal use
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
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.
|
// 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.
|
// 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 {
|
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) {
|
if !idRegex.MatchString(id) {
|
||||||
return ErrInvalidChars
|
return ErrInvalidChars
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user