Skip to content

Commit

Permalink
fix(common): strmatcher match domain safety
Browse files Browse the repository at this point in the history
  • Loading branch information
mengskysama authored and yuhan6665 committed Aug 24, 2023
1 parent cd1d000 commit fce86aa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion common/strmatcher/ac_automaton_matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,11 @@ func (ac *ACAutomaton) Match(s string) bool {
// 2. the match string is through a fail edge. NOT FULL MATCH
// 2.1 Through a fail edge, but there exists a valid node. SUBSTR
for i := len(s) - 1; i >= 0; i-- {
idx := char2Index[s[i]]
chr := int(s[i])
if chr >= len(char2Index) {
return false
}
idx := char2Index[chr]
fullMatch = fullMatch && ac.trie[node][idx].edgeType
node = ac.trie[node][idx].nextNode
switch ac.exists[node].matchType {
Expand Down
5 changes: 4 additions & 1 deletion common/strmatcher/strmatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,17 @@ func TestACAutomaton(t *testing.T) {
pattern: "vvgoogle.com",
res: true,
},
{
pattern: "½",
res: false,
},
}
for _, test := range cases2Output {
if m := ac.Match(test.pattern); m != test.res {
t.Error("unexpected output: ", m, " for test case ", test)
}
}
}

{
cases3Input := []struct {
pattern string
Expand Down

0 comments on commit fce86aa

Please sign in to comment.