Skip to content
This repository was archived by the owner on Feb 13, 2024. It is now read-only.

Commit 6c76619

Browse files
committed
add IsAny method for matchers package
1 parent 667c814 commit 6c76619

File tree

5 files changed

+33
-23
lines changed

5 files changed

+33
-23
lines changed

internal/runner/validator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func customs(options *common.Options) {
103103
matchers.IsBlank(rules[j].Element, "Custom threat rules element")
104104
elm := fmt.Sprint("$", rules[j].Element)
105105

106-
if !matchers.IsMatch(fmt.Sprint(`\`, elm), cfg.Logformat) {
106+
if !matchers.IsAny(elm, cfg.Logformat) {
107107
err = strings.Replace(errors.ErrNoElement, ":element", elm, -1)
108108
err = strings.Replace(err, ":category", custom[i].Name, -1)
109109

pkg/matchers/fuzz.go

Lines changed: 0 additions & 9 deletions
This file was deleted.

pkg/matchers/matchers.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package matchers
2+
3+
import (
4+
"regexp"
5+
"strings"
6+
7+
"github.com/sahilm/fuzzy"
8+
)
9+
10+
func IsAny(substr string, s string) bool {
11+
if strings.Index(s, substr) > 0 {
12+
return false
13+
}
14+
15+
return true
16+
}
17+
18+
func IsMatch(pattern string, s string) bool {
19+
defer func() {
20+
_ = recover()
21+
}()
22+
23+
re := regexp.MustCompile(pattern)
24+
return re.FindString(s) != ""
25+
}
26+
27+
func IsMatchFuzz(pattern string, s []string) bool {
28+
matches := fuzzy.Find(pattern, s)
29+
30+
return len(matches) > 0
31+
}

pkg/matchers/regex.go

Lines changed: 0 additions & 12 deletions
This file was deleted.

pkg/teler/teler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func Analyze(options *common.Options, logs *gonx.Entry) (bool, map[string]string
229229
cont = strings.ReplaceAll(cont, `.%EXT%`, ext)
230230
}
231231

232-
match = matchers.IsMatch(trimFirst(req.Path), cont)
232+
match = matchers.IsAny(trimFirst(req.Path), cont)
233233
}
234234
}
235235

0 commit comments

Comments
 (0)