From 478470f609b0435ab5179d7a9e0e73719d9c9c09 Mon Sep 17 00:00:00 2001 From: Andy Hsu Date: Sun, 31 Dec 2023 15:03:25 +0800 Subject: [PATCH] feat!: replace regex package (close #5755) --- go.mod | 1 + go.sum | 2 ++ internal/model/obj.go | 10 +++++----- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 30ff10b3fbb..e6e8bc60130 100644 --- a/go.mod +++ b/go.mod @@ -19,6 +19,7 @@ require ( github.com/deckarep/golang-set/v2 v2.3.1 github.com/disintegration/imaging v1.6.2 github.com/djherbis/times v1.5.0 + github.com/dlclark/regexp2 v1.10.0 github.com/dustinxie/ecc v0.0.0-20210511000915-959544187564 github.com/foxxorcat/mopan-sdk-go v0.1.4 github.com/foxxorcat/weiyun-sdk-go v0.1.3 diff --git a/go.sum b/go.sum index 7d7048f8377..a763a1ace13 100644 --- a/go.sum +++ b/go.sum @@ -119,6 +119,8 @@ github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1 github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4= github.com/djherbis/times v1.5.0 h1:79myA211VwPhFTqUk8xehWrsEO+zcIZj0zT8mXPVARU= github.com/djherbis/times v1.5.0/go.mod h1:5q7FDLvbNg1L/KaBmPcWlVR9NmoKo3+ucqUA3ijQhA0= +github.com/dlclark/regexp2 v1.10.0 h1:+/GIL799phkJqYW+3YbOd8LCcbHzT0Pbo8zl70MHsq0= +github.com/dlclark/regexp2 v1.10.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= github.com/dustinxie/ecc v0.0.0-20210511000915-959544187564 h1:I6KUy4CI6hHjqnyJLNCEi7YHVMkwwtfSr2k9splgdSM= github.com/dustinxie/ecc v0.0.0-20210511000915-959544187564/go.mod h1:yekO+3ZShy19S+bsmnERmznGy9Rfg6dWWWpiGJjNAz8= github.com/foxxorcat/mopan-sdk-go v0.1.4 h1:6utvPiBv8KDRDVKB7A4FERdrVxcHKZd2fBFCNuKcXzU= diff --git a/internal/model/obj.go b/internal/model/obj.go index 77c0700a35c..dbcdcaf12a3 100644 --- a/internal/model/obj.go +++ b/internal/model/obj.go @@ -2,13 +2,13 @@ package model import ( "io" - "regexp" "sort" "strings" "time" "github.com/alist-org/alist/v3/pkg/http_range" "github.com/alist-org/alist/v3/pkg/utils" + "github.com/dlclark/regexp2" mapset "github.com/deckarep/golang-set/v2" @@ -169,7 +169,7 @@ func NewObjMerge() *ObjMerge { } type ObjMerge struct { - regs []*regexp.Regexp + regs []*regexp2.Regexp set mapset.Set[string] } @@ -190,7 +190,7 @@ func (om *ObjMerge) insertObjs(objs []Obj, objs_ ...Obj) []Obj { func (om *ObjMerge) clickObj(obj Obj) bool { for _, reg := range om.regs { - if reg.MatchString(obj.GetName()) { + if isMatch, _ := reg.MatchString(obj.GetName()); isMatch { return false } } @@ -199,9 +199,9 @@ func (om *ObjMerge) clickObj(obj Obj) bool { func (om *ObjMerge) InitHideReg(hides string) { rs := strings.Split(hides, "\n") - om.regs = make([]*regexp.Regexp, 0, len(rs)) + om.regs = make([]*regexp2.Regexp, 0, len(rs)) for _, r := range rs { - om.regs = append(om.regs, regexp.MustCompile(r)) + om.regs = append(om.regs, regexp2.MustCompile(r, regexp2.None)) } }