From 0145758e7030dba8c94d33956af72866dc449c97 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Tue, 7 Mar 2023 17:21:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96URL=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/serverconfigs/shared/url_pattern.go | 2 +- pkg/serverconfigs/shared/url_pattern_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/serverconfigs/shared/url_pattern.go b/pkg/serverconfigs/shared/url_pattern.go index 6dcd237..bf9554a 100644 --- a/pkg/serverconfigs/shared/url_pattern.go +++ b/pkg/serverconfigs/shared/url_pattern.go @@ -34,7 +34,7 @@ func (this *URLPattern) Init() error { for index, piece := range pieces { pieces[index] = regexp.QuoteMeta(piece) } - reg, err := regexp.Compile("(?i)" /** 大小写不敏感 **/ + strings.Join(pieces, "(.*)")) + reg, err := regexp.Compile("(?i)" /** 大小写不敏感 **/ + "^" + strings.Join(pieces, "(.*)") + "$") if err != nil { return err } diff --git a/pkg/serverconfigs/shared/url_pattern_test.go b/pkg/serverconfigs/shared/url_pattern_test.go index 1e7fa43..121482a 100644 --- a/pkg/serverconfigs/shared/url_pattern_test.go +++ b/pkg/serverconfigs/shared/url_pattern_test.go @@ -43,6 +43,12 @@ func TestURLPattern_Match(t *testing.T) { url: "https://example.com", result: true, }, + { + patternType: "wildcard", + pattern: "*COM", + url: "https://example.com/hello", + result: false, + }, { patternType: "wildcard", pattern: "http://*",