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

Commit

Permalink
Handle string read receipt data (#10606)
Browse files Browse the repository at this point in the history
* Handle string read receipt data

Signed-off-by: Šimon Brandner <[email protected]>

* Test that we handle string read receipt data

Signed-off-by: Šimon Brandner <[email protected]>

* Add changelog for #10606

Signed-off-by: Šimon Brandner <[email protected]>

* Add docs

Signed-off-by: Šimon Brandner <[email protected]>

* Ignore malformed RRs

Signed-off-by: Šimon Brandner <[email protected]>

* Only surround hidden = ...

Signed-off-by: Šimon Brandner <[email protected]>

* Remove unnecessary argument

Signed-off-by: Šimon Brandner <[email protected]>

* Update changelog.d/10606.bugfix

Co-authored-by: Andrew Morgan <[email protected]>
  • Loading branch information
SimonBrandner and anoadragon453 authored Aug 16, 2021
1 parent d1f43b7 commit a3a7514
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/10606.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix errors on /sync when read receipt data is a string. Only affects homeservers with the experimental flag for [MSC2285](https://github.com/matrix-org/matrix-doc/pull/2285) enabled. Contributed by @SimonBrandner.
9 changes: 8 additions & 1 deletion synapse/handlers/receipts.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,14 @@ def filter_out_hidden(events: List[JsonDict], user_id: str) -> List[JsonDict]:

new_users = {}
for rr_user_id, user_rr in m_read.items():
hidden = user_rr.get("hidden", None)
try:
hidden = user_rr.get("hidden")
except AttributeError:
# Due to https://github.com/matrix-org/synapse/issues/10376
# there are cases where user_rr is a string, in those cases
# we just ignore the read receipt
continue

if hidden is not True or rr_user_id == user_id:
new_users[rr_user_id] = user_rr.copy()
# If hidden has a value replace hidden with the correct prefixed key
Expand Down
23 changes: 23 additions & 0 deletions tests/handlers/test_receipts.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,29 @@ def test_filters_out_receipt_event_with_only_hidden_receipt_and_ignores_rest(sel
],
)

def test_handles_string_data(self):
"""
Tests that an invalid shape for read-receipts is handled.
Context: https://github.com/matrix-org/synapse/issues/10603
"""

self._test_filters_hidden(
[
{
"content": {
"$14356419edgd14394fHBLK:matrix.org": {
"m.read": {
"@rikj:jki.re": "string",
}
},
},
"room_id": "!jEsUZKDJdhlrceRyVU:example.org",
"type": "m.receipt",
},
],
[],
)

def _test_filters_hidden(
self, events: List[JsonDict], expected_output: List[JsonDict]
):
Expand Down

0 comments on commit a3a7514

Please sign in to comment.