mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-03-06 06:07:30 +00:00
fix: backticks cannot be used to separate multiple regular expressions in the exclude-filter of proxy-providers
https://github.com/MetaCubeX/mihomo/issues/2259
This commit is contained in:
@@ -331,15 +331,22 @@ func (cp *CompatibleProvider) Close() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewProxiesParser(filter string, excludeFilter string, excludeType string, dialerProxy string, override OverrideSchema) (resource.Parser[[]C.Proxy], error) {
|
func NewProxiesParser(filter string, excludeFilter string, excludeType string, dialerProxy string, override OverrideSchema) (resource.Parser[[]C.Proxy], error) {
|
||||||
excludeFilterReg, err := regexp2.Compile(excludeFilter, regexp2.None)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("invalid excludeFilter regex: %w", err)
|
|
||||||
}
|
|
||||||
var excludeTypeArray []string
|
var excludeTypeArray []string
|
||||||
if excludeType != "" {
|
if excludeType != "" {
|
||||||
excludeTypeArray = strings.Split(excludeType, "|")
|
excludeTypeArray = strings.Split(excludeType, "|")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var excludeFilterRegs []*regexp2.Regexp
|
||||||
|
if excludeFilter != "" {
|
||||||
|
for _, excludeFilter := range strings.Split(excludeFilter, "`") {
|
||||||
|
excludeFilterReg, err := regexp2.Compile(excludeFilter, regexp2.None)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("invalid excludeFilter regex: %w", err)
|
||||||
|
}
|
||||||
|
excludeFilterRegs = append(excludeFilterRegs, excludeFilterReg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var filterRegs []*regexp2.Regexp
|
var filterRegs []*regexp2.Regexp
|
||||||
for _, filter := range strings.Split(filter, "`") {
|
for _, filter := range strings.Split(filter, "`") {
|
||||||
filterReg, err := regexp2.Compile(filter, regexp2.None)
|
filterReg, err := regexp2.Compile(filter, regexp2.None)
|
||||||
@@ -367,8 +374,9 @@ func NewProxiesParser(filter string, excludeFilter string, excludeType string, d
|
|||||||
proxies := []C.Proxy{}
|
proxies := []C.Proxy{}
|
||||||
proxiesSet := map[string]struct{}{}
|
proxiesSet := map[string]struct{}{}
|
||||||
for _, filterReg := range filterRegs {
|
for _, filterReg := range filterRegs {
|
||||||
|
LOOP1:
|
||||||
for idx, mapping := range schema.Proxies {
|
for idx, mapping := range schema.Proxies {
|
||||||
if nil != excludeTypeArray && len(excludeTypeArray) > 0 {
|
if len(excludeTypeArray) > 0 {
|
||||||
mType, ok := mapping["type"]
|
mType, ok := mapping["type"]
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
@@ -377,18 +385,11 @@ func NewProxiesParser(filter string, excludeFilter string, excludeType string, d
|
|||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
flag := false
|
for _, excludeType := range excludeTypeArray {
|
||||||
for i := range excludeTypeArray {
|
if strings.EqualFold(pType, excludeType) {
|
||||||
if strings.EqualFold(pType, excludeTypeArray[i]) {
|
continue LOOP1
|
||||||
flag = true
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if flag {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
mName, ok := mapping["name"]
|
mName, ok := mapping["name"]
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -398,9 +399,11 @@ func NewProxiesParser(filter string, excludeFilter string, excludeType string, d
|
|||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if len(excludeFilter) > 0 {
|
if len(excludeFilterRegs) > 0 {
|
||||||
if mat, _ := excludeFilterReg.MatchString(name); mat {
|
for _, excludeFilterReg := range excludeFilterRegs {
|
||||||
continue
|
if mat, _ := excludeFilterReg.MatchString(name); mat {
|
||||||
|
continue LOOP1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(filter) > 0 {
|
if len(filter) > 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user