mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2025-11-04 21:50:26 +08:00
优化URL匹配方法
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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://*",
|
||||
|
||||
Reference in New Issue
Block a user