Restrict --admin-prefix values to same character set as --ignore-file

This commit is contained in:
Seednode 2023-12-31 16:04:54 -06:00
parent 3702cac56e
commit 127e0ffe22
3 changed files with 6 additions and 8 deletions

View File

@ -16,11 +16,11 @@ import (
)
var (
ErrInvalidAdminPrefix = errors.New("admin path must not contain a '/'")
ErrInvalidAdminPrefix = errors.New("admin path must match the pattern " + AllowedCharacters)
ErrInvalidConcurrency = errors.New("concurrency limit must be between 1 and 8192 inclusive")
ErrInvalidFileCountRange = errors.New("maximum file count limit must be greater than or equal to minimum file count limit")
ErrInvalidFileCountValue = errors.New("file count limits must be non-negative integers no greater than 2147483647")
ErrInvalidIgnoreFile = errors.New("ignore filename must match the pattern " + ignoreFilePattern)
ErrInvalidIgnoreFile = errors.New("ignore filename must match the pattern " + AllowedCharacters)
ErrInvalidPort = errors.New("listen port must be an integer between 1 and 65535 inclusive")
ErrNoMediaFound = errors.New("no supported media formats found which match all criteria")
)

View File

@ -22,8 +22,6 @@ import (
"seedno.de/seednode/roulette/types"
)
const ignoreFilePattern string = `^[A-z0-9.\-_]+$`
type regexes struct {
alphanumeric *regexp.Regexp
filename *regexp.Regexp

View File

@ -8,13 +8,13 @@ import (
"log"
"math"
"regexp"
"strings"
"github.com/spf13/cobra"
)
const (
ReleaseVersion string = "3.5.2"
AllowedCharacters string = `^[A-z0-9.\-_]+$`
ReleaseVersion string = "3.5.3"
)
var (
@ -79,9 +79,9 @@ var (
return ErrInvalidPort
case Concurrency < 1 || Concurrency > 8192:
return ErrInvalidConcurrency
case Ignore && !regexp.MustCompile(ignoreFilePattern).MatchString(IgnoreFile):
case Ignore && !regexp.MustCompile(AllowedCharacters).MatchString(IgnoreFile):
return ErrInvalidIgnoreFile
case strings.Contains(AdminPrefix, "/"):
case AdminPrefix != "" && !regexp.MustCompile(AllowedCharacters).MatchString(AdminPrefix):
return ErrInvalidAdminPrefix
case AdminPrefix != "":
AdminPrefix = "/" + AdminPrefix