changeset 3920:993cc8e56aef

core (xmpp): check presence of some keys in attachment before using them: in `completeAttachments` `url` was used to complete a missing name, but it may be missing with some attachments, thus its presence is now checked.
author Goffi <goffi@goffi.org>
date Thu, 06 Oct 2022 16:02:05 +0200
parents 7b2c51bcc8f5
children cc2705225778
files sat/core/xmpp.py
diffstat 1 files changed, 3 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/sat/core/xmpp.py	Thu Oct 06 16:02:05 2022 +0200
+++ b/sat/core/xmpp.py	Thu Oct 06 16:02:05 2022 +0200
@@ -1302,11 +1302,12 @@
     def completeAttachments(self, data):
         """Complete missing metadata of attachments"""
         for attachment in data['extra'].get(C.MESS_KEY_ATTACHMENTS, []):
-            if "name" not in attachment:
+            if "name" not in attachment and "url" in attachment:
                 name = (Path(unquote(urlparse(attachment['url']).path)).name
                         or C.FILE_DEFAULT_NAME)
                 attachment["name"] = name
-            if C.MESS_KEY_ATTACHMENTS_MEDIA_TYPE not in attachment:
+            if ((C.MESS_KEY_ATTACHMENTS_MEDIA_TYPE not in attachment
+                 and "name" in attachment)):
                 media_type = mimetypes.guess_type(attachment['name'], strict=False)[0]
                 if media_type:
                     attachment[C.MESS_KEY_ATTACHMENTS_MEDIA_TYPE] = media_type