Skip to content

Commit

Permalink
feat(utils): add inThreatRegexp func
Browse files Browse the repository at this point in the history
  • Loading branch information
dwisiswant0 committed Sep 5, 2023
1 parent 0dfae23 commit 12ea1d9
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"errors"
"html"
"io"
"regexp"
"strings"

"net/http"
Expand All @@ -35,6 +36,16 @@ func (t *Teler) inThreatIndex(kind threat.Threat, substr string) bool {
return false
}

// inThreatRegexp checks if the given pattern 'p' is match against threat datasets
func (t *Teler) inThreatRegexp(kind threat.Threat, p string) (bool, error) {
var pattern strings.Builder
pattern.WriteString("(?m)^")
pattern.WriteString(regexp.QuoteMeta(p))
pattern.WriteString("$")

return regexp.MatchString(pattern.String(), t.threat.data[kind])
}

// setDSLRequestEnv will set DSL environment based on the incoming request information.
func (t *Teler) setDSLRequestEnv(r *http.Request) {
// Converts map of headers to RAW string
Expand Down

0 comments on commit 12ea1d9

Please sign in to comment.