From edc96985f75167179823eb56553b5ab0bcebab90 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Sun, 29 May 2022 19:54:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B0=83=E6=95=B4not=E8=A7=84=E5=88=99?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E5=AD=90=E8=A7=84=E5=88=99=E6=95=B0=E9=87=8F?= =?UTF-8?q?=EF=BC=8C=E9=80=BB=E8=BE=91=E8=A7=84=E5=88=99=E8=BF=94=E5=9B=9E?= =?UTF-8?q?payload=E9=87=87=E7=94=A8=E8=A7=A3=E6=9E=90=E5=90=8E=E7=BB=93?= =?UTF-8?q?=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rule/logic/and.go | 6 ++++++ rule/logic/not.go | 11 +++++------ rule/logic/or.go | 5 +++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/rule/logic/and.go b/rule/logic/and.go index 1d4c99f7..f2d54379 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 4d56bd2a..20fb90c5 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 05ad6f91..b79188c3 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 }