Software /
code /
prosody
Changeset
7239:c9af793b2d8f
util.xml: Correct stanza.namespaces table construction when duplicate prefix names are encountered in the element tree.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sat, 05 Mar 2016 17:51:35 -0500 |
parents | 7238:7df4e385b248 |
children | 7240:bf8aa0d1951c |
files | util/xml.lua |
diffstat | 1 files changed, 11 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/util/xml.lua Sat Mar 05 20:50:17 2016 +0000 +++ b/util/xml.lua Sat Mar 05 17:51:35 2016 -0500 @@ -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 @@ --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 @@ 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