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 ( 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") 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") 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") 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") 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") ErrNoMediaFound = errors.New("no supported media formats found which match all criteria")
) )

View File

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

View File

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