# HG changeset patch # User Kim Alvefur # Date 1601134247 -7200 # Node ID 5e09a3389adb2bf8abd0ff41a53bb1edca04fd95 # Parent 4d12a6785531926dd488bdcb7b49c635ed008f9e util.stanza: Support inclusion of URI from util.error object diff -r 4d12a6785531 -r 5e09a3389adb spec/util_stanza_spec.lua --- a/spec/util_stanza_spec.lua Sat Sep 26 17:26:31 2020 +0200 +++ b/spec/util_stanza_spec.lua Sat Sep 26 17:30:47 2020 +0200 @@ -247,6 +247,11 @@ assert.are.equal(r.tags[1].tags[1].name, e.condition); assert.are.equal(r.tags[1].tags[2]:get_text(), e.text); assert.are.equal("this.test", r.tags[1].attr.by); + + local gone = errors.new({ condition = "gone", extra = { uri = "file:///dev/null" } }) + local gonner = st.error_reply(s, gone); + assert.are.equal("gone", gonner.tags[1].tags[1].name); + assert.are.equal("file:///dev/null", gonner.tags[1].tags[1][1]); end); end); diff -r 4d12a6785531 -r 5e09a3389adb util/stanza.lua --- a/util/stanza.lua Sat Sep 26 17:26:31 2020 +0200 +++ b/util/stanza.lua Sat Sep 26 17:30:47 2020 +0200 @@ -455,9 +455,11 @@ end local t = reply(orig); t.attr.type = "error"; + local extra; if type(error_type) == "table" then -- an util.error or similar object if type(error_type.extra) == "table" then - if type(error_type.extra.by) == "string" then error_by = error_type.extra.by; end + extra = error_type.extra; + if type(extra.by) == "string" then error_by = extra.by; end end error_type, condition, error_message = error_type.type, error_type.condition, error_type.text; end @@ -465,7 +467,11 @@ error_by = nil; end t:tag("error", {type = error_type, by = error_by}) --COMPAT: Some day xmlns:stanzas goes here - :tag(condition, xmpp_stanzas_attr):up(); + :tag(condition, xmpp_stanzas_attr); + if extra and condition == "gone" and type(extra.uri) == "string" then + t:text(extra.uri); + end + t:up(); if error_message then t:text_tag("text", error_message, xmpp_stanzas_attr); end return t; -- stanza ready for adding app-specific errors end