aboutsummaryrefslogtreecommitdiffstats
path: root/util/stanza.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2013-04-03 13:38:27 +0100
committerMatthew Wild <mwild1@gmail.com>2013-04-03 13:38:27 +0100
commit3230dc4c0a66f96726a190e30fdf67e64b8c15b8 (patch)
treef9f150358ed1e45f642e8ff3ee6b967d12a942d3 /util/stanza.lua
parent245f4609913fed7a5c83ed1f931d3175843ad8c5 (diff)
downloadprosody-3230dc4c0a66f96726a190e30fdf67e64b8c15b8.tar.gz
prosody-3230dc4c0a66f96726a190e30fdf67e64b8c15b8.zip
util.stanza: :maptags(): Fixes to make loop more robust on item removal
Diffstat (limited to 'util/stanza.lua')
-rw-r--r--util/stanza.lua6
1 files changed, 4 insertions, 2 deletions
diff --git a/util/stanza.lua b/util/stanza.lua
index a0ab2a5a..213ed506 100644
--- a/util/stanza.lua
+++ b/util/stanza.lua
@@ -153,7 +153,7 @@ function stanza_mt:maptags(callback)
local n_children, n_tags = #self, #tags;
local i = 1;
- while curr_tag <= n_tags do
+ while curr_tag <= n_tags and n_tags > 0 do
if self[i] == tags[curr_tag] then
local ret = callback(self[i]);
if ret == nil then
@@ -161,13 +161,15 @@ function stanza_mt:maptags(callback)
t_remove(tags, curr_tag);
n_children = n_children - 1;
n_tags = n_tags - 1;
+ i = i - 1;
+ curr_tag = curr_tag - 1;
else
self[i] = ret;
tags[i] = ret;
end
- i = i + 1;
curr_tag = curr_tag + 1;
end
+ i = i + 1;
end
return self;
end