Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Properly preserve an empty dict.
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep committed May 10, 2023
1 parent 938e878 commit 1bb7208
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
11 changes: 5 additions & 6 deletions synapse/events/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,12 @@ def add_fields(*fields: str) -> None:
if room_version.msc3821_redaction_rules:
# Preserve the signed field under third_party_invite.
third_party_invite = event_dict["content"].get("third_party_invite")
if third_party_invite and isinstance(
third_party_invite, collections.abc.Mapping
):
if isinstance(third_party_invite, collections.abc.Mapping):
new_content["third_party_invite"] = {}
if "signed" in third_party_invite:
new_content["third_party_invite"] = {
"signed": third_party_invite["signed"]
}
new_content["third_party_invite"]["signed"] = third_party_invite[
"signed"
]

elif event_type == EventTypes.Create:
# MSC2176 rules state that create events cannot be redacted.
Expand Down
18 changes: 18 additions & 0 deletions tests/events/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,24 @@ def test_member(self) -> None:
)

# Ensure this doesn't break if an invalid field is sent.
self.run_test(
{
"type": "m.room.member",
"content": {
"membership": "invite",
"third_party_invite": {},
"other_key": "stripped",
},
},
{
"type": "m.room.member",
"content": {"membership": "invite", "third_party_invite": {}},
"signatures": {},
"unsigned": {},
},
room_version=RoomVersions.MSC3821,
)

self.run_test(
{
"type": "m.room.member",
Expand Down

0 comments on commit 1bb7208

Please sign in to comment.