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

Commit

Permalink
Allow backslashes in event field filters
Browse files Browse the repository at this point in the history
Fixes a bug introduced in #1783 which
meant that single backslashes were not allowed in event field filters.

The intention here is to allow single-backslashes, but disallow
double-backslashes.
  • Loading branch information
richvdh committed Oct 24, 2018
1 parent e0b9d5f commit 7e07d25
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.d/4083.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug which prevented backslashes being used in event field filters
5 changes: 4 additions & 1 deletion synapse/api/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@
# 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"^((?!\\\\).)*$"
}
}
},
Expand Down
12 changes: 11 additions & 1 deletion tests/api/test_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_errors_on_invalid_filters(self):
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"]}},
Expand Down Expand Up @@ -109,6 +109,16 @@ def test_valid_filters(self):
"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:
Expand Down

0 comments on commit 7e07d25

Please sign in to comment.