Software /
code /
prosody
Changeset
5414:efec29eb4cdd
util.stanza: :maptags(): Fixes to make loop more robust on item removal
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 03 Apr 2013 13:38:27 +0100 |
parents | 5413:0bf5e90be086 |
children | 5415:9e7aa5b47bdf |
files | util/stanza.lua |
diffstat | 1 files changed, 4 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/util/stanza.lua Wed Apr 03 08:14:55 2013 +0100 +++ b/util/stanza.lua Wed Apr 03 13:38:27 2013 +0100 @@ -153,7 +153,7 @@ 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 @@ 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