From bc4402a6a1d6337abc6c7678441023d8d9a37e75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Gim=C3=A9nez?= Date: Mon, 13 Mar 2023 21:49:46 +0900 Subject: [PATCH] chain evaluation returns true in case of nothing to eval, also fixed stat layer comparison --- pkg/itemfilter/chain.go | 4 ++++ pkg/itemfilter/itemfilter.go | 2 +- pkg/nip/nip_parser.go | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/itemfilter/chain.go b/pkg/itemfilter/chain.go index e0d7f8c..88f32e5 100644 --- a/pkg/itemfilter/chain.go +++ b/pkg/itemfilter/chain.go @@ -19,6 +19,10 @@ func (ch *evaluationChain) Add(result bool, operand nip.Operand) { } func (ch *evaluationChain) Evaluate() bool { + if len(ch.links) == 0 { + return true + } + if len(ch.links) == 1 { return ch.links[0].Result } diff --git a/pkg/itemfilter/itemfilter.go b/pkg/itemfilter/itemfilter.go index 2d61e64..ef4eae4 100644 --- a/pkg/itemfilter/itemfilter.go +++ b/pkg/itemfilter/itemfilter.go @@ -61,7 +61,7 @@ func checkStat(i data.Item, cmp nip.Comparable) bool { return true } - return st[2] == itemStat.Layer + return st[1] == itemStat.Layer } func checkProperty(i data.Item, prop nip.Comparable) bool { diff --git a/pkg/nip/nip_parser.go b/pkg/nip/nip_parser.go index d530c1d..6f22f5f 100644 --- a/pkg/nip/nip_parser.go +++ b/pkg/nip/nip_parser.go @@ -27,7 +27,7 @@ func ParseLine(line string) (Rule, error) { } var stats []Group - if len(lineSplit) > 1 { + if len(lineSplit) > 1 && strings.TrimSpace(lineSplit[1]) != "" { stats, err = buildGroups(lineSplit[1]) if err != nil { return Rule{}, err @@ -35,7 +35,7 @@ func ParseLine(line string) (Rule, error) { } var maxQuantity []Group - if len(lineSplit) > 2 { + if len(lineSplit) > 2 && strings.TrimSpace(lineSplit[2]) != "" { maxQuantity, err = buildGroups(lineSplit[2]) if err != nil { return Rule{}, err