From f6944f639003c2923477673cc0b1afea27b5b22f Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 28 Sep 2022 11:04:15 +0300 Subject: [PATCH] Don't match state_key push rules for non-state events --- pushrules/condition.go | 2 +- pushrules/condition_eventmatch_test.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pushrules/condition.go b/pushrules/condition.go index 4748feaa..f809f8e7 100644 --- a/pushrules/condition.go +++ b/pushrules/condition.go @@ -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": diff --git a/pushrules/condition_eventmatch_test.go b/pushrules/condition_eventmatch_test.go index 82bb6b54..aab4b205 100644 --- a/pushrules/condition_eventmatch_test.go +++ b/pushrules/condition_eventmatch_test.go @@ -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{}{})