diff mod_xmllang_check/mod_xmllang_check.lua @ 6401:de3dc4297035

mod_xmllang_check: Initial commit
author Waqas Hussain <waqas20@gmail.com>
date Mon, 09 Feb 2026 18:34:40 -0500
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mod_xmllang_check/mod_xmllang_check.lua	Mon Feb 09 18:34:40 2026 -0500
@@ -0,0 +1,22 @@
+-- Strip invalid xml:lang values from outgoing s2s stanzas.
+--
+-- xmpplang.lib.lua must return a function that validates xml:lang strings.
+local is_valid_xml_lang = module:require "xmpplang";
+
+local function strip_invalid_xml_lang(element)
+	local xml_lang = element.attr["xml:lang"];
+	if xml_lang ~= nil and not is_valid_xml_lang(xml_lang, element) then
+		element.attr["xml:lang"] = nil;
+	end
+
+	for child in element:childtags() do
+		strip_invalid_xml_lang(child);
+	end
+end
+
+module:hook("route/remote", function (event)
+	-- FIXME should we clone the stanza vs modifying in place?
+	-- FIXME should we replace recursively vs checking a specific subset of elements?
+	-- FIXME instead of outgoing, should we clean incoming stanzas from everywhere, so invalid xml:lang stanzas are never sent or stored?
+	strip_invalid_xml_lang(event.stanza);
+end, 500);