0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-12-14 18:53:53 +01:00

fix the check for whether is_url to match all the other ones in codebase (#3405)

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2019-01-06 21:43:26 +00:00 committed by Richard van der Hoff
parent 29f20a8a1a
commit a27e501b09
2 changed files with 9 additions and 3 deletions

1
changelog.d/3405.bugfix Normal file
View file

@ -0,0 +1 @@
Fix contains_url check to be consistent with other instances in code-base and check that value is an instance of string.

View file

@ -12,6 +12,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from six import text_type
import jsonschema import jsonschema
from canonicaljson import json from canonicaljson import json
from jsonschema import FormatChecker from jsonschema import FormatChecker
@ -353,7 +355,7 @@ class Filter(object):
sender = event.user_id sender = event.user_id
room_id = None room_id = None
ev_type = "m.presence" ev_type = "m.presence"
is_url = False contains_url = False
else: else:
sender = event.get("sender", None) sender = event.get("sender", None)
if not sender: if not sender:
@ -368,13 +370,16 @@ class Filter(object):
room_id = event.get("room_id", None) room_id = event.get("room_id", None)
ev_type = event.get("type", None) ev_type = event.get("type", None)
is_url = "url" in event.get("content", {})
content = event.get("content", {})
# check if there is a string url field in the content for filtering purposes
contains_url = isinstance(content.get("url"), text_type)
return self.check_fields( return self.check_fields(
room_id, room_id,
sender, sender,
ev_type, ev_type,
is_url, contains_url,
) )
def check_fields(self, room_id, sender, event_type, contains_url): def check_fields(self, room_id, sender, event_type, contains_url):