Philipp Hörist pushed to branch master at gajim / gajim
Commits: 2a595826 by mjk at 2022-12-08T22:55:46+00:00 fix: Preview: Don't treat multi-line message body as previewable URL
- - - - -
1 changed file:
- gajim/common/preview.py
Changes:
===================================== gajim/common/preview.py ===================================== @@ -21,6 +21,7 @@
import logging import os +import re from pathlib import Path from urllib.parse import urlparse from urllib.parse import ParseResult @@ -33,6 +34,7 @@
from gajim.common import app from gajim.common import configpaths +from gajim.common import regex from gajim.common.const import MIME_TYPES from gajim.common.helpers import AdditionalDataDict from gajim.common.helpers import load_file_async @@ -53,6 +55,8 @@
log = logging.getLogger('gajim.c.preview')
+IRI_RX = re.compile(regex.IRI) + PREVIEWABLE_MIME_TYPES = get_previewable_mime_types() mime_types = set(MIME_TYPES) # Merge both: if it’s a previewable image, it should be allowed @@ -333,8 +337,9 @@ def _accept_uri(urlparts: ParseResult, def is_previewable(self, text: str, additional_data: AdditionalDataDict) -> bool: - if len(text.split(' ')) > 1: - # urlparse doesn't recognise spaces as URL delimiter + if not IRI_RX.fullmatch(text): + # urlparse removes whitespace (and who knows what else) from URLs, + # so can't be used for validation. return False
uri = text
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/2a5958265717a72181156511bb8521c44...