diff options
author | Richard van der Hoff <1389908+richvdh@users.noreply.github.com> | 2018-10-24 12:05:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-24 12:05:19 +0100 |
commit | 78e8d4c3a5e44649f70f6f45b47eb849ae3b9efe (patch) | |
tree | 741c28822a3b5e26d229be68bc06c95a25218748 | |
parent | Merge pull request #4082 from matrix-org/rav/fix_pep8 (diff) | |
parent | Merge remote-tracking branch 'origin/develop' into rav/fix_event_filter_valid... (diff) | |
download | synapse-78e8d4c3a5e44649f70f6f45b47eb849ae3b9efe.tar.xz |
Merge pull request #4083 from matrix-org/rav/fix_event_filter_validation
Allow backslashes in event field filters
Diffstat (limited to '')
-rw-r--r-- | changelog.d/4083.bugfix | 1 | ||||
-rw-r--r-- | synapse/api/filtering.py | 5 | ||||
-rw-r--r-- | tests/api/test_filtering.py | 12 |
3 files changed, 16 insertions, 2 deletions
diff --git a/changelog.d/4083.bugfix b/changelog.d/4083.bugfix new file mode 100644 index 0000000000..b3b08cdfa6 --- /dev/null +++ b/changelog.d/4083.bugfix @@ -0,0 +1 @@ +Fix bug which prevented backslashes being used in event field filters \ No newline at end of file diff --git a/synapse/api/filtering.py b/synapse/api/filtering.py index eed8c67e6a..677c0bdd4c 100644 --- a/synapse/api/filtering.py +++ b/synapse/api/filtering.py @@ -172,7 +172,10 @@ USER_FILTER_SCHEMA = { # events a lot easier as we can then use a negative lookbehind # assertion to split '\.' If we allowed \\ then it would # 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"^((?!\\\\).)*$" } } }, diff --git a/tests/api/test_filtering.py b/tests/api/test_filtering.py index 48b2d3d663..2a7044801a 100644 --- a/tests/api/test_filtering.py +++ b/tests/api/test_filtering.py @@ -60,7 +60,7 @@ class FilteringTestCase(unittest.TestCase): invalid_filters = [ {"boom": {}}, {"account_data": "Hello World"}, - {"event_fields": ["\\foo"]}, + {"event_fields": [r"\\foo"]}, {"room": {"timeline": {"limit": 0}, "state": {"not_bars": ["*"]}}}, {"event_format": "other"}, {"room": {"not_rooms": ["#foo:pik-test"]}}, @@ -109,6 +109,16 @@ class FilteringTestCase(unittest.TestCase): "event_format": "client", "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: try: |