changeset 3856:8bdb1729529b

mod_rest: Make XHTML-IM mapping more convenient Avoid burdening web developers with XML namespace attribute Might be a bit fragile Note that the <body> element must be included
author Kim Alvefur <zash@zash.se>
date Sat, 25 Jan 2020 00:46:09 +0100
parents 0e1e900577c4
children 8752e5b5dd08
files mod_rest/jsonmap.lib.lua
diffstat 1 files changed, 2 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mod_rest/jsonmap.lib.lua	Sat Jan 25 00:43:28 2020 +0100
+++ b/mod_rest/jsonmap.lib.lua	Sat Jan 25 00:46:09 2020 +0100
@@ -25,15 +25,14 @@
 	join = {"bool_tag", "http://jabber.org/protocol/muc", "x"},
 
 	-- XEP-0071
-	-- FIXME xmlns is awkward
 	html = {
 		"func", "http://jabber.org/protocol/xhtml-im", "html",
 		function (s) --> json string
-			return tostring(s:get_child("body", "http://www.w3.org/1999/xhtml"));
+			return (tostring(s:get_child("body", "http://www.w3.org/1999/xhtml")):gsub(" xmlns='[^']*'","", 1));
 		end;
 		function (s) --> xml
 			if type(s) == "string" then
-				return xml.parse([[<html xmlns='http://jabber.org/protocol/xhtml-im'>]]..s..[[</html>]]);
+				return assert(xml.parse([[<x:html xmlns:x='http://jabber.org/protocol/xhtml-im' xmlns='http://www.w3.org/1999/xhtml'>]]..s..[[</x:html>]]));
 			end
 		end;
 	};