Philipp Hörist pushed to branch master at gajim / gajim


Commits:
b290723d by Philipp Hörist at 2026-02-27T17:40:22+01:00
fix: Preview: Trigger only https urls with a specific length

- - - - -
58f66c19 by Philipp Hörist at 2026-02-27T17:58:01+01:00
fix: Preview: Don't display preview if a site has no title

- - - - -


3 changed files:

- gajim/common/open_graph_parser.py
- gajim/common/regex.py
- gajim/gtk/message_url_previews.py


Changes:

=====================================
gajim/common/open_graph_parser.py
=====================================
@@ -119,7 +119,10 @@ def parse(self, text: str) -> OpenGraphData | None:
         except EOF:
             pass
 
-        if "title" not in self._attributes and self._fallback_title:
+        if "title" not in self._attributes:
+            if not self._fallback_title:
+                return None
+
             self._attributes["title"] = self._fallback_title
 
         if "description" not in self._attributes and 
self._fallback_description:


=====================================
gajim/common/regex.py
=====================================
@@ -82,8 +82,10 @@
 ifragment      = fr'(?:{ipchar}|[/?])*'
 scheme         = fr'(?P<scheme>{ALPHA}[a-zA-Z0-9+.-]*)'
 IRI            = fr'{scheme}:{ihier_part}(?:\?{iquery})?(?:#{ifragment})?'
+HTTPS_URL       = fr'https://{ihier_part}(?:\?{iquery})?(?:#{ifragment})?'
 
 IRI_RX = re.compile(IRI)
+HTTPS_URL_RX = re.compile(HTTPS_URL)
 
 # <https://rfc-editor.org/rfc/rfc7564#section-4.2>
 class PRECIS:


=====================================
gajim/gtk/message_url_previews.py
=====================================
@@ -20,7 +20,7 @@
 from gajim.common.multiprocess.http import CancelledError
 from gajim.common.multiprocess.url_preview import generate_url_preview
 from gajim.common.open_graph_parser import OpenGraphData
-from gajim.common.regex import IRI_RX
+from gajim.common.regex import HTTPS_URL_RX
 from gajim.common.types import ChatContactT
 
 from gajim.gtk.preview.open_graph import OpenGraphPreviewWidget
@@ -111,9 +111,12 @@ def _find_urls(self, text: str) -> None:
         self._preview_timeout_id = None
 
         # We use lists here to preserve a stable and consistent order
-        matches = itertools.islice(re.finditer(IRI_RX, text), MAX_URL_PREVIEWS)
+        matches = itertools.islice(re.finditer(HTTPS_URL_RX, text), 
MAX_URL_PREVIEWS)
         urls = [match.group() for match in matches]
 
+        # Don't trigger on unrealistic short urls
+        urls = list(filter(lambda u: len(u) > 10, urls))
+
         # Remove dismissed urls if they are not present in the text anymore
         self._dismissed_previews = set(urls) & self._dismissed_previews
 



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/compare/18da32aa129a07945a9dfb4405901d96ff9c3313...58f66c191b9f1672c4ce49b0538390c65da3ca36

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/compare/18da32aa129a07945a9dfb4405901d96ff9c3313...58f66c191b9f1672c4ce49b0538390c65da3ca36
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to