From dfe81f6f23b1bf60d07a18ff8090e2f9b124bae1 Mon Sep 17 00:00:00 2001 From: wweir Date: Thu, 28 Feb 2019 17:38:34 +0800 Subject: [PATCH] Fix suffix tree match logic --- util/suffix_tree.go | 8 ++++++-- util/suffix_tree_test.go | 10 ++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/util/suffix_tree.go b/util/suffix_tree.go index 9cd5ead..ff59765 100644 --- a/util/suffix_tree.go +++ b/util/suffix_tree.go @@ -88,10 +88,14 @@ func (n *node) matchSecs(secs []string, fuzzNode bool) bool { } if n, ok := n.node[secs[length-1]]; ok { - return n.matchSecs(secs[:length-1], false) + if n.matchSecs(secs[:length-1], false) { + return true + } } if n, ok := n.node["*"]; ok { - return n.matchSecs(secs[:length-1], true) + if n.matchSecs(secs[:length-1], true) { + return true + } } if _, ok := n.node["**"]; ok { return true diff --git a/util/suffix_tree_test.go b/util/suffix_tree_test.go index fd92b91..cca33e3 100644 --- a/util/suffix_tree_test.go +++ b/util/suffix_tree_test.go @@ -39,11 +39,12 @@ func TestNode_Match(t *testing.T) { }, }, { "fuzz2", - NewNodeFromRules(".", "a.*.cc"), + NewNodeFromRules(".", "a.*.cc", "c.wweir.*"), []test{ {"wweir.cc", false}, {"a.wweir.cc", true}, {"b.wweir.cc", false}, + {"c.wweir.cc", true}, }, }, { "fuzz3", @@ -56,13 +57,14 @@ func TestNode_Match(t *testing.T) { }, }, { "fuzz4", - NewNodeFromRules(".", "**.cc", "a.**.com"), + NewNodeFromRules(".", "**.cc", "a.**.com", "**.wweir.*"), []test{ {"wweir.cc", true}, {"a.wweir.cc", true}, {"a.b.wweir.cc", true}, - {"a.wweir.com", true}, - {"b.wweir.com", false}, + {"a.fuzz.com", true}, + {"b.fuzz.com", false}, + {"www.wweir.com", true}, }, }} for _, tt := range tests {