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

Convert boolean event content to strings for push rule evaluation #12181

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/12181.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Convert event content booleans to strings when evaluating push rules. Contributed by Nick @ Beeper.
2 changes: 2 additions & 0 deletions synapse/push/push_rule_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ def _flatten_dict(
if result is None:
result = {}
for key, value in d.items():
if isinstance(value, bool):
value = str(value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this implementation because it will give "True" and "False" as strings. Other languages represent them differently. The encoding of booleans as strings should really be specified unambiguously so push rules can be written to work on any homeserver.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, the below string check lowercases them but it's not explicit in any way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, well, it feels less bad then (Python's capitalisation is particularly unusual, I guess), but I suppose we still ought to make it explicit in the spec how things should be stringified if this is what we're doing.

if isinstance(value, str):
result[".".join(prefix + [key])] = value.lower()
elif isinstance(value, Mapping):
Expand Down