aboutsummaryrefslogtreecommitdiff
path: root/rules_manager.go
diff options
context:
space:
mode:
authorEmiliano Ciavatta2021-07-28 18:12:14 +0000
committerEmiliano Ciavatta2021-07-28 18:12:14 +0000
commit99cfe84c23f3beb8baf76b799ace1b3ffbf1d5ff (patch)
tree41d8bbbe2f46051aeebf5b4ae73c46325c4bf7c6 /rules_manager.go
parentfdb0bf97d2dec72adf08e5f2d7ad65b560d8cf8e (diff)
parentf60d7cb1da70d439cd401e2fa4b7ecccec41bfe4 (diff)
Merge branch 'release/1.21.0' into main
Diffstat (limited to 'rules_manager.go')
-rw-r--r--rules_manager.go24
1 files changed, 18 insertions, 6 deletions
diff --git a/rules_manager.go b/rules_manager.go
index 5d6cded..ed1932d 100644
--- a/rules_manager.go
+++ b/rules_manager.go
@@ -21,12 +21,14 @@ import (
"context"
"errors"
"fmt"
- "github.com/flier/gohs/hyperscan"
- "github.com/go-playground/validator/v10"
- log "github.com/sirupsen/logrus"
"sort"
+ "strings"
"sync"
"time"
+
+ "github.com/flier/gohs/hyperscan"
+ "github.com/go-playground/validator/v10"
+ log "github.com/sirupsen/logrus"
)
const DirectionBoth = 0
@@ -313,11 +315,20 @@ func (rm *rulesManagerImpl) validateAndAddRuleLocal(rule *Rule) error {
return err
}
+ regex := pattern.Regex
+ if !strings.HasPrefix(regex, "/") {
+ regex = fmt.Sprintf("/%s", regex)
+ }
+ if !strings.HasSuffix(regex, "/") {
+ regex = fmt.Sprintf("%s/", regex)
+ }
+ rule.Patterns[i].Regex = regex
+
compiledPattern, err := pattern.BuildPattern()
if err != nil {
return err
}
- regex := compiledPattern.String()
+ regex = compiledPattern.String()
if _, isPresent := duplicatePatterns[regex]; isPresent {
return errors.New("duplicate pattern")
}
@@ -336,7 +347,8 @@ func (rm *rulesManagerImpl) validateAndAddRuleLocal(rule *Rule) error {
startID := len(rm.patterns)
for id, pattern := range newPatterns {
rm.patterns = append(rm.patterns, pattern)
- rm.patternsIds[pattern.String()] = uint(startID + id)
+ regex := pattern.String()
+ rm.patternsIds[regex[strings.IndexByte(regex, ':')+1:]] = uint(startID + id)
}
rm.rules[rule.ID] = *rule
@@ -363,7 +375,7 @@ func (rm *rulesManagerImpl) generateDatabase(version RowID) error {
}
func (p *Pattern) BuildPattern() (*hyperscan.Pattern, error) {
- hp, err := hyperscan.ParsePattern(fmt.Sprintf("/%s/", p.Regex))
+ hp, err := hyperscan.ParsePattern(p.Regex)
if err != nil {
return nil, err
}