@ -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
}