Skip to content
Snippets Groups Projects
Unverified Commit 78e8d4c3 authored by Richard van der Hoff's avatar Richard van der Hoff Committed by GitHub
Browse files

Merge pull request #4083 from matrix-org/rav/fix_event_filter_validation

Allow backslashes in event field filters
parents 73280391 3ad359e5
No related branches found
No related tags found
No related merge requests found
Fix bug which prevented backslashes being used in event field filters
\ No newline at end of file
...@@ -172,7 +172,10 @@ USER_FILTER_SCHEMA = { ...@@ -172,7 +172,10 @@ USER_FILTER_SCHEMA = {
# events a lot easier as we can then use a negative lookbehind # events a lot easier as we can then use a negative lookbehind
# assertion to split '\.' If we allowed \\ then it would # assertion to split '\.' If we allowed \\ then it would
# incorrectly split '\\.' See synapse.events.utils.serialize_event # incorrectly split '\\.' See synapse.events.utils.serialize_event
"pattern": "^((?!\\\).)*$" #
# Note that because this is a regular expression, we have to escape
# each backslash in the pattern.
"pattern": r"^((?!\\\\).)*$"
} }
} }
}, },
......
...@@ -60,7 +60,7 @@ class FilteringTestCase(unittest.TestCase): ...@@ -60,7 +60,7 @@ class FilteringTestCase(unittest.TestCase):
invalid_filters = [ invalid_filters = [
{"boom": {}}, {"boom": {}},
{"account_data": "Hello World"}, {"account_data": "Hello World"},
{"event_fields": ["\\foo"]}, {"event_fields": [r"\\foo"]},
{"room": {"timeline": {"limit": 0}, "state": {"not_bars": ["*"]}}}, {"room": {"timeline": {"limit": 0}, "state": {"not_bars": ["*"]}}},
{"event_format": "other"}, {"event_format": "other"},
{"room": {"not_rooms": ["#foo:pik-test"]}}, {"room": {"not_rooms": ["#foo:pik-test"]}},
...@@ -109,6 +109,16 @@ class FilteringTestCase(unittest.TestCase): ...@@ -109,6 +109,16 @@ class FilteringTestCase(unittest.TestCase):
"event_format": "client", "event_format": "client",
"event_fields": ["type", "content", "sender"], "event_fields": ["type", "content", "sender"],
}, },
# a single backslash should be permitted (though it is debatable whether
# it should be permitted before anything other than `.`, and what that
# actually means)
#
# (note that event_fields is implemented in
# synapse.events.utils.serialize_event, and so whether this actually works
# is tested elsewhere. We just want to check that it is allowed through the
# filter validation)
{"event_fields": [r"foo\.bar"]},
] ]
for filter in valid_filters: for filter in valid_filters:
try: try:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment