Mercurial > prosody-hg
comparison util/stanza.lua @ 12724:5b5b428d67e2 0.12
util.stanza: Return nil instead of nothing (fix test with luassert >=1.9)
Due to a change in luassert, a dependency luassert of the Busted test
framework, returning nothing is no longer treated as not falsy.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 15 Sep 2022 11:05:21 +0200 |
| parents | 1a4c61253932 |
| children | 12ced5db29b2 3784a8ce0596 |
comparison
equal
deleted
inserted
replaced
| 12679:7d4a95ba9b6c | 12724:5b5b428d67e2 |
|---|---|
| 162 or child.attr.xmlns == xmlns) then | 162 or child.attr.xmlns == xmlns) then |
| 163 | 163 |
| 164 return child; | 164 return child; |
| 165 end | 165 end |
| 166 end | 166 end |
| 167 return nil; | |
| 167 end | 168 end |
| 168 | 169 |
| 169 function stanza_mt:get_child_text(name, xmlns) | 170 function stanza_mt:get_child_text(name, xmlns) |
| 170 local tag = self:get_child(name, xmlns); | 171 local tag = self:get_child(name, xmlns); |
| 171 if tag then | 172 if tag then |
| 176 | 177 |
| 177 function stanza_mt:child_with_name(name) | 178 function stanza_mt:child_with_name(name) |
| 178 for _, child in ipairs(self.tags) do | 179 for _, child in ipairs(self.tags) do |
| 179 if child.name == name then return child; end | 180 if child.name == name then return child; end |
| 180 end | 181 end |
| 182 return nil; | |
| 181 end | 183 end |
| 182 | 184 |
| 183 function stanza_mt:child_with_ns(ns) | 185 function stanza_mt:child_with_ns(ns) |
| 184 for _, child in ipairs(self.tags) do | 186 for _, child in ipairs(self.tags) do |
| 185 if child.attr.xmlns == ns then return child; end | 187 if child.attr.xmlns == ns then return child; end |
| 186 end | 188 end |
| 189 return nil; | |
| 187 end | 190 end |
| 188 | 191 |
| 189 function stanza_mt:get_child_with_attr(name, xmlns, attr_name, attr_value, normalize) | 192 function stanza_mt:get_child_with_attr(name, xmlns, attr_name, attr_value, normalize) |
| 190 for tag in self:childtags(name, xmlns) do | 193 for tag in self:childtags(name, xmlns) do |
| 191 if (normalize and normalize(tag.attr[attr_name]) or tag.attr[attr_name]) == attr_value then | 194 if (normalize and normalize(tag.attr[attr_name]) or tag.attr[attr_name]) == attr_value then |
| 192 return tag; | 195 return tag; |
| 193 end | 196 end |
| 194 end | 197 end |
| 198 return nil; | |
| 195 end | 199 end |
| 196 | 200 |
| 197 function stanza_mt:children() | 201 function stanza_mt:children() |
| 198 local i = 0; | 202 local i = 0; |
| 199 return function (a) | 203 return function (a) |
| 348 | 352 |
| 349 function stanza_mt.get_text(t) | 353 function stanza_mt.get_text(t) |
| 350 if #t.tags == 0 then | 354 if #t.tags == 0 then |
| 351 return t_concat(t); | 355 return t_concat(t); |
| 352 end | 356 end |
| 357 return nil; | |
| 353 end | 358 end |
| 354 | 359 |
| 355 function stanza_mt.get_error(stanza) | 360 function stanza_mt.get_error(stanza) |
| 356 local error_type, condition, text, extra_tag; | 361 local error_type, condition, text, extra_tag; |
| 357 | 362 |
