From 601a16b5cb56b4fa2716ceb79c55b7e7fd1f6acc Mon Sep 17 00:00:00 2001 From: DirtyRacer1337 Date: Thu, 5 Sep 2024 09:59:05 +0700 Subject: [PATCH] replace stashBox validation (#5187) --- internal/manager/config/config.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/manager/config/config.go b/internal/manager/config/config.go index d56d3359b..3cba5e1f2 100644 --- a/internal/manager/config/config.go +++ b/internal/manager/config/config.go @@ -2,6 +2,7 @@ package config import ( "fmt" + "net/url" "os" "path/filepath" "reflect" @@ -1097,7 +1098,10 @@ func (i *Config) ValidateCredentials(username string, password string) bool { return username == authUser && err == nil } -var stashBoxRe = regexp.MustCompile("^http.*graphql$") +func stashBoxValidate(str string) bool { + u, err := url.Parse(str) + return err == nil && u.Scheme != "" && u.Host != "" && strings.HasSuffix(u.Path, "/graphql") +} type StashBoxInput struct { Endpoint string `json:"endpoint"` @@ -1118,7 +1122,7 @@ func (i *Config) ValidateStashBoxes(boxes []*StashBoxInput) error { return &StashBoxError{msg: "endpoint cannot be blank"} } - if !stashBoxRe.Match([]byte(box.Endpoint)) { + if !stashBoxValidate(box.Endpoint) { return &StashBoxError{msg: "endpoint is invalid"} }