From 3616ae870a8d1eb3d03b84ea4b9dc84c4c6d603f Mon Sep 17 00:00:00 2001 From: nite07 Date: Thu, 15 Feb 2024 15:35:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E6=9C=AC=E5=9C=B0=E6=A8=A1=E6=9D=BF=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/controller/default.go | 11 +++++++---- validator/sub.go | 9 ++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/api/controller/default.go b/api/controller/default.go index 53ae47e..20bca76 100644 --- a/api/controller/default.go +++ b/api/controller/default.go @@ -31,9 +31,8 @@ func BuildSub(clashType model.ClashType, query validator.SubValidator, template if query.Template != "" { template = query.Template } - _, err = url.ParseRequestURI(template) - if err != nil { - templateBytes, err = utils.LoadTemplate(template) + if strings.HasPrefix(template, "http") { + templateBytes, err = utils.LoadSubscription(template, query.Refresh) if err != nil { logger.Logger.Debug( "load template failed", zap.String("template", template), zap.Error(err), @@ -41,7 +40,11 @@ func BuildSub(clashType model.ClashType, query validator.SubValidator, template return nil, errors.New("加载模板失败: " + err.Error()) } } else { - templateBytes, err = utils.LoadSubscription(template, query.Refresh) + unescape, err := url.QueryUnescape(template) + if err != nil { + return nil, errors.New("加载模板失败: " + err.Error()) + } + templateBytes, err = utils.LoadTemplate(unescape) if err != nil { logger.Logger.Debug( "load template failed", zap.String("template", template), zap.Error(err), diff --git a/validator/sub.go b/validator/sub.go index 4ed6a9e..ea9dd8d 100644 --- a/validator/sub.go +++ b/validator/sub.go @@ -5,7 +5,6 @@ import ( "encoding/hex" "errors" "net/url" - "os" "regexp" "strings" @@ -73,13 +72,13 @@ func ParseQuery(c *gin.Context) (SubValidator, error) { query.Proxies = nil } if query.Template != "" { - uri, err := url.ParseRequestURI(query.Template) - if err != nil { - if strings.Contains(query.Template, string(os.PathSeparator)) { + if strings.HasPrefix(query.Template, "http") { + uri, err := url.ParseRequestURI(query.Template) + if err != nil { return SubValidator{}, err } + query.Template = uri.String() } - query.Template = uri.String() } if query.RuleProvider != "" { reg := regexp.MustCompile(`\[(.*?)\]`)