fix: 调整not规则判断子规则数量,逻辑规则返回payload采用解析后结果

This commit is contained in:
gVisor bot 2022-05-29 19:54:11 +08:00
parent 993f9f1441
commit edc96985f7
3 changed files with 16 additions and 6 deletions

View file

@ -1,8 +1,10 @@
package logic package logic
import ( import (
"fmt"
C "github.com/Dreamacro/clash/constant" C "github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/clash/rule/common" "github.com/Dreamacro/clash/rule/common"
"strings"
) )
type AND struct { type AND struct {
@ -25,13 +27,17 @@ func NewAND(payload string, adapter string) (*AND, error) {
} }
and.rules = rules and.rules = rules
payloads := make([]string, 0, len(rules))
for _, rule := range rules { for _, rule := range rules {
payloads = append(payloads, fmt.Sprintf("(%s)", rule.Payload()))
if rule.ShouldResolveIP() { if rule.ShouldResolveIP() {
and.needIP = true and.needIP = true
break break
} }
} }
and.payload = strings.Join(payloads, " && ")
return and, nil return and, nil
} }

View file

@ -18,19 +18,18 @@ func (not *NOT) ShouldFindProcess() bool {
} }
func NewNOT(payload string, adapter string) (*NOT, error) { func NewNOT(payload string, adapter string) (*NOT, error) {
not := &NOT{Base: &common.Base{}, payload: payload, adapter: adapter} not := &NOT{Base: &common.Base{}, adapter: adapter}
rule, err := parseRuleByPayload(payload) rule, err := parseRuleByPayload(payload)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if len(rule) > 1 { if len(rule) != 1 {
return nil, fmt.Errorf("not rule can contain at most one rule") return nil, fmt.Errorf("not rule must contain one rule")
} }
if len(rule) > 0 { not.rule = rule[0]
not.rule = rule[0] not.payload = fmt.Sprintf("!(%s)", rule[0].Payload())
}
return not, nil return not, nil
} }

View file

@ -1,8 +1,10 @@
package logic package logic
import ( import (
"fmt"
C "github.com/Dreamacro/clash/constant" C "github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/clash/rule/common" "github.com/Dreamacro/clash/rule/common"
"strings"
) )
type OR struct { type OR struct {
@ -51,12 +53,15 @@ func NewOR(payload string, adapter string) (*OR, error) {
} }
or.rules = rules or.rules = rules
payloads := make([]string, 0, len(rules))
for _, rule := range rules { for _, rule := range rules {
payloads = append(payloads, fmt.Sprintf("(%s)", rule.Payload()))
if rule.ShouldResolveIP() { if rule.ShouldResolveIP() {
or.needIP = true or.needIP = true
break break
} }
} }
or.payload = strings.Join(payloads, " || ")
return or, nil return or, nil
} }