Skip to content

Commit

Permalink
Fix suffix tree match logic
Browse files Browse the repository at this point in the history
  • Loading branch information
wweir committed Feb 28, 2019
1 parent 972875e commit dfe81f6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 6 additions & 2 deletions util/suffix_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions util/suffix_tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 {
Expand Down

0 comments on commit dfe81f6

Please sign in to comment.