Don't match state_key push rules for non-state events

This commit is contained in:
Tulir Asokan 2022-09-28 11:04:15 +03:00
commit f6944f6390
2 changed files with 9 additions and 1 deletions

View file

@ -155,7 +155,7 @@ func (cond *PushCondition) matchValue(room Room, evt *event.Event) bool {
return pattern.MatchString(string(evt.RoomID))
case "state_key":
if evt.StateKey == nil {
return cond.Pattern == ""
return false
}
return pattern.MatchString(*evt.StateKey)
case "content":

View file

@ -60,9 +60,17 @@ func TestPushCondition_Match_KindEvent_RoomID(t *testing.T) {
func TestPushCondition_Match_KindEvent_BlankStateKey(t *testing.T) {
condition := newMatchPushCondition("state_key", "")
evt := newFakeEvent(event.NewEventType("m.room.foo"), &struct{}{})
blankString := ""
evt.StateKey = &blankString
assert.True(t, condition.Match(blankTestRoom, evt))
}
func TestPushCondition_Match_KindEvent_NonStateStateKey(t *testing.T) {
condition := newMatchPushCondition("state_key", "")
evt := newFakeEvent(event.NewEventType("m.room.foo"), &struct{}{})
assert.False(t, condition.Match(blankTestRoom, evt))
}
func TestPushCondition_Match_KindEvent_BlankStateKey_Fail(t *testing.T) {
condition := newMatchPushCondition("state_key", "not blank")
evt := newFakeEvent(event.NewEventType("m.room.foo"), &struct{}{})