aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2024-11-17 13:40:20 +0100
committerKim Alvefur <zash@zash.se>2024-11-17 13:40:20 +0100
commit885fde62be7244c5b2c978c97dcac0e80a1c9450 (patch)
treec68c111d3633acf0e091b90791ef1f03e1e56039
parent00584c4d610a381e4181ab438102420aa601f310 (diff)
downloadprosody-885fde62be7244c5b2c978c97dcac0e80a1c9450.tar.gz
prosody-885fde62be7244c5b2c978c97dcac0e80a1c9450.zip
util.stanza: Handle Clark notation for attributes in :find()
-rw-r--r--spec/util_stanza_spec.lua1
-rw-r--r--util/stanza.lua3
2 files changed, 4 insertions, 0 deletions
diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua
index cabb27bf..f79f8cb9 100644
--- a/spec/util_stanza_spec.lua
+++ b/spec/util_stanza_spec.lua
@@ -580,6 +580,7 @@ describe("util.stanza", function()
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);
diff --git a/util/stanza.lua b/util/stanza.lua
index 325c494e..2f4e964a 100644
--- a/util/stanza.lua
+++ b/util/stanza.lua
@@ -277,6 +277,9 @@ function stanza_mt:find(path)
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];