From 14a805c36296f6454ffc14a6ec94c03bdadd74b1 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Wed, 27 Oct 2021 10:25:57 -0400 Subject: [PATCH] Clarify use of content. --- synapse/api/filtering.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/synapse/api/filtering.py b/synapse/api/filtering.py index f8ada80a6b8c..4b0a9b29744d 100644 --- a/synapse/api/filtering.py +++ b/synapse/api/filtering.py @@ -327,16 +327,19 @@ def check(self, event: FilterEvent) -> bool: } return self._check_fields(field_matchers) else: + content = event.get("content") + # Content is assumed to be a dict below, so ensure it is. This should + # always be true for events, but account_data has been allowed to + # have non-dict content. + if not isinstance(content, dict): + content = {} + sender = event.get("sender", None) - content = event.get("content") or {} if not sender: # Presence events had their 'sender' in content.user_id, but are # now handled above. We don't know if anything else uses this # form. TODO: Check this and probably remove it. - # account_data has been allowed to have non-dict content, so - # check type first - if isinstance(content, dict): - sender = content.get("user_id") + sender = content.get("user_id") room_id = event.get("room_id", None) ev_type = event.get("type", None)