summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorPatrick Cloke <clokep@users.noreply.github.com>2023-02-08 13:09:41 -0500
committerGitHub <noreply@github.com>2023-02-08 13:09:41 -0500
commitc951fbedcb81895c199c1f4cfe2251d6c3a7b5f4 (patch)
treed93fe5b70b38da87f3daaf1192fd4a9333ddb4fa /tests
parentDocument how to run Synapse (#15022) (diff)
downloadsynapse-c951fbedcb81895c199c1f4cfe2251d6c3a7b5f4.tar.xz
MSC3873: Escape keys when flattening dicts. (#15004)
This disambiguates keys which attempt to match fields
with a dot in them (e.g. m.relates_to).

Disabled by default behind an experimental configuration flag.
Diffstat (limited to 'tests')
-rw-r--r--tests/push/test_push_rule_evaluator.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/push/test_push_rule_evaluator.py b/tests/push/test_push_rule_evaluator.py
index da33423871..516b65cc3c 100644
--- a/tests/push/test_push_rule_evaluator.py
+++ b/tests/push/test_push_rule_evaluator.py
@@ -48,6 +48,14 @@ class FlattenDictTestCase(unittest.TestCase):
         input = {"foo": {"bar": "abc"}}
         self.assertEqual({"foo.bar": "abc"}, _flatten_dict(input))
 
+        # If a field has a dot in it, escape it.
+        input = {"m.foo": {"b\\ar": "abc"}}
+        self.assertEqual({"m.foo.b\\ar": "abc"}, _flatten_dict(input))
+        self.assertEqual(
+            {"m\\.foo.b\\\\ar": "abc"},
+            _flatten_dict(input, msc3783_escape_event_match_key=True),
+        )
+
     def test_non_string(self) -> None:
         """Non-string items are dropped."""
         input: Dict[str, Any] = {