Add regex validation (#3424)

This commit is contained in:
DingDongSoLong4 2023-02-13 01:48:10 +02:00 committed by GitHub
parent d2865b0796
commit ca38a355d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"path/filepath"
"regexp"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/internal/manager/config"
@ -227,10 +228,22 @@ func (r *mutationResolver) ConfigureGeneral(ctx context.Context, input ConfigGen
}
if input.Excludes != nil {
for _, r := range input.Excludes {
_, err := regexp.Compile(r)
if err != nil {
return makeConfigGeneralResult(), fmt.Errorf("video exclusion pattern '%v' invalid: %w", r, err)
}
}
c.Set(config.Exclude, input.Excludes)
}
if input.ImageExcludes != nil {
for _, r := range input.ImageExcludes {
_, err := regexp.Compile(r)
if err != nil {
return makeConfigGeneralResult(), fmt.Errorf("image/gallery exclusion pattern '%v' invalid: %w", r, err)
}
}
c.Set(config.ImageExclude, input.ImageExcludes)
}
@ -464,6 +477,12 @@ func (r *mutationResolver) ConfigureScraping(ctx context.Context, input ConfigSc
}
if input.ExcludeTagPatterns != nil {
for _, r := range input.ExcludeTagPatterns {
_, err := regexp.Compile(r)
if err != nil {
return makeConfigScrapingResult(), fmt.Errorf("tag exclusion pattern '%v' invalid: %w", r, err)
}
}
c.Set(config.ScraperExcludeTagPatterns, input.ExcludeTagPatterns)
}