This commit is contained in:
bluepython508 committed 2026-02-19 10:07:43 +00:00
1 parent 007438e372
commit 6e637ecf77
1763 files changed
+60820 -279516

No files matched your search

+18 -6
View File
@@ -9,7 +9,6 @@ import (
"bytes"
"errors"
"net/http"
"regexp"
"strings"
)
@@ -21,10 +20,6 @@ var (
ErrInvalidShareName = errors.New("Share names may only contain the letters a-z, underscore _, parentheses (), or spaces")
)
var (
shareNameRegex = regexp.MustCompile(`^[a-z0-9_\(\) ]+$`)
)
// AllowShareAs reports whether sharing files as a specific user is allowed.
func AllowShareAs() bool {
return !DisallowShareAs && doAllowShareAs()
@@ -125,9 +120,26 @@ func NormalizeShareName(name string) (string, error) {
// Trim whitespace
name = strings.TrimSpace(name)
if !shareNameRegex.MatchString(name) {
if !validShareName(name) {
return "", ErrInvalidShareName
}
return name, nil
}
func validShareName(name string) bool {
if name == "" {
return false
}
for _, r := range name {
if 'a' <= r && r <= 'z' || '0' <= r && r <= '9' {
continue
}
switch r {
case '_', ' ', '(', ')':
continue
}
return false
}
return true
}