mirror of
https://github.com/tailscale/tailscale.git
synced 2025-10-27 11:41:14 +00:00
drive: don't use regexp package in leaf types package
Even with ts_omit_drive, the drive package is currently still imported for some types. So it should be light. But it was depending on the "regexp" packge, which I'd like to remove from our minimal builds. Updates #12614 Change-Id: I5bf85d8eb15a739793723b1da11c370d3fcd2f32 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
b9cdef18c0
commit
bbb16e4e72
@@ -9,7 +9,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -21,10 +20,6 @@ var (
|
|||||||
ErrInvalidShareName = errors.New("Share names may only contain the letters a-z, underscore _, parentheses (), or spaces")
|
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.
|
// AllowShareAs reports whether sharing files as a specific user is allowed.
|
||||||
func AllowShareAs() bool {
|
func AllowShareAs() bool {
|
||||||
return !DisallowShareAs && doAllowShareAs()
|
return !DisallowShareAs && doAllowShareAs()
|
||||||
@@ -125,9 +120,26 @@ func NormalizeShareName(name string) (string, error) {
|
|||||||
// Trim whitespace
|
// Trim whitespace
|
||||||
name = strings.TrimSpace(name)
|
name = strings.TrimSpace(name)
|
||||||
|
|
||||||
if !shareNameRegex.MatchString(name) {
|
if !validShareName(name) {
|
||||||
return "", ErrInvalidShareName
|
return "", ErrInvalidShareName
|
||||||
}
|
}
|
||||||
|
|
||||||
return name, nil
|
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
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user