diff --git a/rule/logic/and.go b/rule/logic/and.go index 1d4c99f78..f2d543790 100644 --- a/rule/logic/and.go +++ b/rule/logic/and.go @@ -1,8 +1,10 @@ package logic import ( + "fmt" C "github.com/Dreamacro/clash/constant" "github.com/Dreamacro/clash/rule/common" + "strings" ) type AND struct { @@ -25,13 +27,17 @@ func NewAND(payload string, adapter string) (*AND, error) { } and.rules = rules + payloads := make([]string, 0, len(rules)) for _, rule := range rules { + payloads = append(payloads, fmt.Sprintf("(%s)", rule.Payload())) if rule.ShouldResolveIP() { and.needIP = true break } } + and.payload = strings.Join(payloads, " && ") + return and, nil } diff --git a/rule/logic/not.go b/rule/logic/not.go index 4d56bd2a6..20fb90c5a 100644 --- a/rule/logic/not.go +++ b/rule/logic/not.go @@ -18,19 +18,18 @@ func (not *NOT) ShouldFindProcess() bool { } 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) if err != nil { return nil, err } - if len(rule) > 1 { - return nil, fmt.Errorf("not rule can contain at most one rule") + if len(rule) != 1 { + 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 } diff --git a/rule/logic/or.go b/rule/logic/or.go index 05ad6f91e..b79188c3a 100644 --- a/rule/logic/or.go +++ b/rule/logic/or.go @@ -1,8 +1,10 @@ package logic import ( + "fmt" C "github.com/Dreamacro/clash/constant" "github.com/Dreamacro/clash/rule/common" + "strings" ) type OR struct { @@ -51,12 +53,15 @@ func NewOR(payload string, adapter string) (*OR, error) { } or.rules = rules + payloads := make([]string, 0, len(rules)) for _, rule := range rules { + payloads = append(payloads, fmt.Sprintf("(%s)", rule.Payload())) if rule.ShouldResolveIP() { or.needIP = true break } } + or.payload = strings.Join(payloads, " || ") return or, nil }