aboutsummaryrefslogtreecommitdiffstats
path: root/util/xml.lua
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2016-03-05 17:51:35 -0500
committerWaqas Hussain <waqas20@gmail.com>2016-03-05 17:51:35 -0500
commit6ce9431a13b57f16f50e65be5e21bda59e57d82b (patch)
tree2f01313ae263ab3c47ba0a0fa42bd811b4e7c95b /util/xml.lua
parent9fc74d1c41dcaa0b256255c5ca1a96621157d270 (diff)
downloadprosody-6ce9431a13b57f16f50e65be5e21bda59e57d82b.tar.gz
prosody-6ce9431a13b57f16f50e65be5e21bda59e57d82b.zip
util.xml: Correct stanza.namespaces table construction when duplicate prefix names are encountered in the element tree.
Diffstat (limited to 'util/xml.lua')
-rw-r--r--util/xml.lua16
1 files changed, 11 insertions, 5 deletions
diff --git a/util/xml.lua b/util/xml.lua
index 9e12f0df..ec06fb01 100644
--- a/util/xml.lua
+++ b/util/xml.lua
@@ -1,6 +1,8 @@
local st = require "util.stanza";
local lxp = require "lxp";
+local t_insert = table.insert;
+local t_remove = table.remove;
local _ENV = nil;
@@ -14,15 +16,19 @@ local parse_xml = (function()
--luacheck: ignore 212/self
local handler = {};
local stanza = st.stanza("root");
- local namespaces = {}
+ local namespaces = {};
+ local prefixes = {};
function handler:StartNamespaceDecl(prefix, url)
if prefix ~= nil then
- namespaces[prefix] = url
+ t_insert(namespaces, url);
+ t_insert(prefixes, prefix);
end
end
function handler:EndNamespaceDecl(prefix)
if prefix ~= nil then
- namespaces[prefix] = nil
+ -- we depend on each StartNamespaceDecl having a paired EndNamespaceDecl
+ t_remove(namespaces);
+ t_remove(prefixes);
end
end
function handler:StartElement(tagname, attr)
@@ -46,8 +52,8 @@ local parse_xml = (function()
end
end
local n = {}
- for prefix, url in pairs(namespaces) do
- n[prefix] = url
+ for i=1,#namespaces do
+ n[prefixes[i]] = namespaces[i];
end
stanza:tag(name, attr, n);
end