Skip to content

Commit

Permalink
chore: strongly threw regexp error
Browse files Browse the repository at this point in the history
  • Loading branch information
mzz2017 committed Mar 7, 2024
1 parent d9f0bd4 commit 54bf936
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ var (

log.Infof("Include config files: [%v]", strings.Join(includes, ", "))
if err := Run(log, conf, []string{filepath.Dir(cfgFile)}); err != nil {
logrus.Fatalln(err)
log.Fatalln(err)
}
},
}
Expand Down
18 changes: 8 additions & 10 deletions component/outbound/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,11 @@ func (s *DialerSet) filterHit(dialer *dialer.Dialer, filters []*config_parser.Fu
for _, param := range filter.Params {
switch param.Key {
case FilterKey_Name_Regex:
var matched bool
if regex, err := regexp2.Compile(param.Val, 0); err == nil {
matched, _ = regex.MatchString(dialer.Property().Name)
} else {
s.log.Warnf("Bad regexp %v: %v", param.Val, err)
regex, err := regexp2.Compile(param.Val, 0)
if err != nil {
return false, fmt.Errorf("bad regexp in %v: %w", filter.String(false, false, true), err)
}
matched, _ := regex.MatchString(dialer.Property().Name)
//logrus.Warnln(param.Val, matched, dialer.Name())
if matched {
subFilterHit = true
Expand All @@ -107,12 +106,11 @@ func (s *DialerSet) filterHit(dialer *dialer.Dialer, filters []*config_parser.Fu
for _, param := range filter.Params {
switch param.Key {
case FilterInput_SubscriptionTag_Regex:
var matched bool
if regex, err := regexp2.Compile(param.Val, 0); err == nil {
matched, _ = regex.MatchString(s.nodeToTagMap[dialer])
} else {
s.log.Warnf("Bad regexp %v: %v", param.Val, err)
regex, err := regexp2.Compile(param.Val, 0)
if err != nil {
return false, fmt.Errorf("bad regexp: %v: %w", param.Val, err)
}
matched, _ := regex.MatchString(s.nodeToTagMap[dialer])
if matched {
subFilterHit = true
break loop2
Expand Down

0 comments on commit 54bf936

Please sign in to comment.