Philipp Hörist pushed to branch master at gajim / python-nbxmpp


Commits:
9391122f by Daniel Brötzmann at 2026-02-22T19:21:48+00:00
change: OGP: Accept only data uris as image

- - - - -


2 changed files:

- nbxmpp/modules/ogp.py
- test/unit/test_ogp.py


Changes:

=====================================
nbxmpp/modules/ogp.py
=====================================
@@ -51,7 +51,15 @@ class OpenGraph(BaseModule):
         data = OpenGraphData()
         for field in fields(OpenGraphData):
             tag = field.name
-            node = description.getTag(tag, namespace=Namespace.OPEN_GRAPH)
-            if node is not None:
-                setattr(data, tag, node.getData())
+            if tag == "image":
+                for node in description.getTags(tag, 
namespace=Namespace.OPEN_GRAPH):
+                    node_data = node.getData()
+                    if node_data.startswith("data:image"):
+                        setattr(data, tag, node_data)
+                        break
+
+            else:
+                if node := description.getTag(tag, 
namespace=Namespace.OPEN_GRAPH):
+                    setattr(data, tag, node.getData())
+
         return data


=====================================
test/unit/test_ogp.py
=====================================
@@ -74,7 +74,7 @@ class OpenGraphTest(StanzaHandlerTest):
             OpenGraphData(
                 title="Page Title",
                 url="Canonical URL",
-                image="https://link.to.example.com/image.png";,
+                image="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABDoAAAH",
                 type="website",
                 site_name="Some Website",
                 description="Page Description",
@@ -95,7 +95,9 @@ class OpenGraphTest(StanzaHandlerTest):
         ogp = props["https://the.link.example.com/what-was-linked-to";]
         self.assertEqual(ogp.title, "Page Title")
         self.assertEqual(ogp.url, "Canonical URL")
-        self.assertEqual(ogp.image, "https://link.to.example.com/image.png";)
+        self.assertEqual(
+            ogp.image, "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABDoAAAH"
+        )
         self.assertEqual(ogp.type, "website")
         self.assertEqual(ogp.site_name, "Some Website")
         self.assertEqual(ogp.description, "Page Description")
@@ -111,7 +113,7 @@ _DATA = """
         <og:title>Page Title</og:title>
         <og:description>Page Description</og:description>
         <og:url>Canonical URL</og:url>
-        <og:image>https://link.to.example.com/image.png</og:image>
+        
<og:image>data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABDoAAAH</og:image>
         <og:type>website</og:type>
         <og:site_name>Some Website</og:site_name>
     </rdf:Description>



View it on GitLab: 
https://dev.gajim.org/gajim/python-nbxmpp/-/commit/9391122f7bc6e7fbf878ed0226c55958858a763b

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/python-nbxmpp/-/commit/9391122f7bc6e7fbf878ed0226c55958858a763b
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