From 351a8cf9f79f589071c2f2d5ca36201304dd1b21 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Wed, 30 Nov 2022 10:42:41 +0000 Subject: [PATCH] Don't match empty patterns --- internal/pushrules/evaluate.go | 5 +++++ internal/pushrules/evaluate_test.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/pushrules/evaluate.go b/internal/pushrules/evaluate.go index f34dc65a4..4ff9939a6 100644 --- a/internal/pushrules/evaluate.go +++ b/internal/pushrules/evaluate.go @@ -145,6 +145,11 @@ func conditionMatches(cond *Condition, event *gomatrixserverlib.Event, ec Evalua } func patternMatches(key, pattern string, event *gomatrixserverlib.Event) (bool, error) { + // It doesn't make sense for an empty pattern to match anything. + if pattern == "" { + return false, nil + } + re, err := globToRegexp(pattern) if err != nil { return false, err diff --git a/internal/pushrules/evaluate_test.go b/internal/pushrules/evaluate_test.go index f2bd7ff72..c5d5abd2a 100644 --- a/internal/pushrules/evaluate_test.go +++ b/internal/pushrules/evaluate_test.go @@ -114,7 +114,7 @@ func TestConditionMatches(t *testing.T) { // Neither of these should match because `content` is not a full string match, // and `content.body` is not a string value. {"eventMatch", Condition{Kind: EventMatchCondition, Key: "content"}, `{"content":{}}`, false}, - {"eventMatch", Condition{Kind: EventMatchCondition, Key: "content.body", Is: "3"}, `{"content":{"body": 3}}`, false}, + {"eventBodyMatch", Condition{Kind: EventMatchCondition, Key: "content.body", Is: "3"}, `{"content":{"body": 3}}`, false}, {"displayNameNoMatch", Condition{Kind: ContainsDisplayNameCondition}, `{"content":{"body":"something without displayname"}}`, false}, {"displayNameMatch", Condition{Kind: ContainsDisplayNameCondition}, `{"content":{"body":"hello Dear User, how are you?"}}`, true},