diff util/stanza.lua @ 13568:3615590fd9ed

util.stanza: Handle namespace prefixes for attributes in :find() More correct handling of namespaces here. This works with both prefixes from the parser and hacky .attr["foo:bar"]
author Kim Alvefur <zash@zash.se>
date Sun, 17 Nov 2024 12:35:51 +0100
parents d10957394a3c
children 59dacbd637c2
line wrap: on
line diff
--- a/util/stanza.lua	Sat Nov 16 09:20:29 2024 +0100
+++ b/util/stanza.lua	Sun Nov 17 12:35:51 2024 +0100
@@ -277,6 +277,10 @@
 		local xmlns, name, text;
 		local char = s_sub(path, pos, pos);
 		if char == "@" then
+			local prefix, attr = s_match(path, "^([^:]+):(.*)", pos+1);
+			if prefix and self.namespaces and self.namespaces[prefix] then
+				return self.attr[self.namespaces[prefix] .. "\1" .. attr];
+			end
 			return self.attr[s_sub(path, pos + 1)];
 		elseif char == "{" then
 			xmlns, pos = s_match(path, "^([^}]+)}()", pos + 1);