diff mod_ogp/mod_ogp.lua @ 4255:38da10e4b593

mod_ogp: Update parsing logic to catch more cases
author Seve Ferrer <seve@delape.net>
date Wed, 18 Nov 2020 13:48:07 +0100
parents a4e182d7ff0a
children dbfda7f5522d
line wrap: on
line diff
--- a/mod_ogp/mod_ogp.lua	Wed Nov 18 11:16:11 2020 +0100
+++ b/mod_ogp/mod_ogp.lua	Wed Nov 18 13:48:07 2020 +0100
@@ -30,32 +30,40 @@
 			local fastening = st.message({to = to, from = from}):tag("apply-to", {xmlns = "urn:xmpp:fasten:0", id = origin_id})
 			local found_metadata = false
 			local message_body = ""
-			for property, content in response_body:gmatch(ogp_pattern) do
-				module:log("info", property .. "\t" .. content)
-				fastening:tag(
-					"meta",
-					{
-						xmlns = "http://www.w3.org/1999/xhtml",
-						property = property,
-						content = content
-					}
-				):up()
-				found_metadata = true
-				message_body = message_body .. property .. "\t" .. content .. "\n"
+
+			local meta_pattern = [[<meta (.-)/?>]]
+			for match in response_body:gmatch(meta_pattern) do
+				local property = match:match([[property=%s*["']?(og:.-)["']?%s]])
+				if not property then
+					property = match:match([[property=["']?(og:.-)["']$]])
+				end
+
+				local content = match:match([[content=%s*["'](.-)["']%s]])
+				if not content then
+					content = match:match([[content=["']?(.-)["']$]])
+				end
+				if not content then
+					content = match:match([[content=(.-) property]])
+				end
+				if not content then
+					content = match:match([[content=(.-)$]])
+				end
+
+				if property and content then
+					module:log("info", property .. "\t" .. content)
+					fastening:tag(
+						"meta",
+						{
+							xmlns = "http://www.w3.org/1999/xhtml",
+							property = property,
+							content = content
+						}
+					):up()
+					found_metadata = true
+					message_body = message_body .. property .. "\t" .. content .. "\n"
+				end
 			end
-			for content, property in response_body:gmatch(ogp_pattern2) do
-				module:log("info", property .. "\t" .. content)
-				fastening:tag(
-					"meta",
-					{
-						xmlns = "http://www.w3.org/1999/xhtml",
-						property = property,
-						content = content
-					}
-				):up()
-				found_metadata = true
-				message_body = message_body .. property .. "\t" .. content .. "\n"
-			end
+
 
 			if found_metadata then
 				mod_muc.get_room_from_jid(room.jid):broadcast_message(fastening)