Changeset

13569:59dacbd637c2

util.stanza: Handle Clark notation for attributes in :find()
author Kim Alvefur <zash@zash.se>
date Sun, 17 Nov 2024 13:40:20 +0100
parents 13568:3615590fd9ed
children 13570:9b9b224aa3f8
files spec/util_stanza_spec.lua util/stanza.lua
diffstat 2 files changed, 4 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/spec/util_stanza_spec.lua	Sun Nov 17 12:35:51 2024 +0100
+++ b/spec/util_stanza_spec.lua	Sun Nov 17 13:40:20 2024 +0100
@@ -580,6 +580,7 @@
 		it("handles namespaced attributes", function()
 			local s = st.stanza("root", { ["urn:example:namespace\1attr"] = "value" }, { e = "urn:example:namespace" });
 			assert.equal("value", s:find("@e:attr"), "finds prefixed attr")
+			assert.equal("value", s:find("@{urn:example:namespace}attr"), "finds clark attr")
 		end)
 	end);
 end);
--- a/util/stanza.lua	Sun Nov 17 12:35:51 2024 +0100
+++ b/util/stanza.lua	Sun Nov 17 13:40:20 2024 +0100
@@ -277,6 +277,9 @@
 		local xmlns, name, text;
 		local char = s_sub(path, pos, pos);
 		if char == "@" then
+			if s_sub(path, pos + 1, pos + 1) == "{" then
+				return self.attr[s_gsub(s_sub(path, pos+2), "}", "\1", 1)];
+			end
 			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];