Daniel Brötzmann pushed to branch master at gajim / gajim
Commits:
cd9ba697 by cal0pteryx at 2026-04-06T08:57:51+02:00
fix: Link previews: Remove line breaks and strip whitespace
- - - - -
a8546d23 by cal0pteryx at 2026-04-06T08:59:55+02:00
fix: Link preview: Hide overflow to honor rounded corners
- - - - -
3 changed files:
- gajim/common/open_graph_parser.py
- gajim/data/gui/preview/open_graph.ui
- test/common/test_open_graph_parser.py
Changes:
=====================================
gajim/common/open_graph_parser.py
=====================================
@@ -14,6 +14,8 @@
import nbxmpp.structs
+from gajim.common.util.text import to_one_line
+
if typing.TYPE_CHECKING:
from gajim.common.storage.archive import models as mod
@@ -93,19 +95,19 @@ def handle_starttag(self, tag: str, attrs: list[tuple[str,
str | None]]) -> None
case {"property": prop, "content": content} if (
prop in ALLOWED_OG_PROPERTIES and content
):
- self._attributes[prop.removeprefix("og:")] = content[
- :MAX_ATTRIBUTE_SIZE
- ]
+ self._attributes[prop.removeprefix("og:")] = self._cleanup(
+ content[:MAX_ATTRIBUTE_SIZE]
+ )
case {"name": "description", "content": content} if content:
- self._fallback_description = content[:MAX_ATTRIBUTE_SIZE]
+ self._fallback_description =
self._cleanup(content[:MAX_ATTRIBUTE_SIZE])
case _:
pass
def handle_endtag(self, tag: str) -> None:
if tag == "title":
- self._fallback_title = self._current_data
+ self._fallback_title = self._cleanup(self._current_data)
elif tag == "head":
raise EOF
@@ -133,6 +135,9 @@ def parse(self, text: str) -> OpenGraphData | None:
return OpenGraphData(**self._attributes)
+ def _cleanup(self, text: str) -> str:
+ return to_one_line(text).strip()
+
class EOF(Exception):
pass
=====================================
gajim/data/gui/preview/open_graph.ui
=====================================
@@ -6,6 +6,7 @@
<property name="halign">start</property>
<property name="width-request">450</property>
<property name="spacing">12</property>
+ <property name="overflow">hidden</property>
<child>
<object class="GtkBox" id="_content_box">
<property name="hexpand">true</property>
=====================================
test/common/test_open_graph_parser.py
=====================================
@@ -40,9 +40,11 @@
EXAMPLE_2 = """
<title>title</title>
<meta name="description" content="description" />
-<meta property="og:title" content="og title" />
+<meta property="og:title" content="
+
+og title " />
<meta property="og:description" content="og description" />
-"""
+""" # noqa: W291
EXAMPLE_3 = """
<title>title</title>
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/b2b8af660f4cc0000e589d11b0a8d7cfc74ca905...a8546d238cdf89d12253b626360ebf003df2526e
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/b2b8af660f4cc0000e589d11b0a8d7cfc74ca905...a8546d238cdf89d12253b626360ebf003df2526e
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]