Skip to content

Commit

Permalink
fix nil
Browse files Browse the repository at this point in the history
  • Loading branch information
RikaCelery committed Oct 10, 2024
1 parent e810fbf commit e4950df
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,22 @@ func patternMatch(ctx *Ctx, pattern []*PatternSegment, msgs []message.MessageSeg
if !containsOptional(pattern) && len(pattern) != len(msgs) {
return false
}
for i := 0; i < len(pattern); i++ {
if pattern[i].Type != (msgs[i].Type) || !pattern[i].Matcher(ctx, msgs[i]) {
i := 0
j := 0
for i < len(pattern) && j < len(msgs) {
if pattern[i].Type != (msgs[j].Type) || !pattern[i].Matcher(ctx, msgs[j]) {
if pattern[i].Optional {
if _, ok := ctx.State[KEY_PATTERN]; !ok {
ctx.State[KEY_PATTERN] = make([]PatternMatched, 0, 1)
}
ctx.State[KEY_PATTERN] = append(ctx.State[KEY_PATTERN].([]PatternMatched), PatternMatched{})
i++
continue
}
return false
}
i++
j++
}
return true
}
Expand Down

0 comments on commit e4950df

Please sign in to comment.