diff options
author | Kim Alvefur <zash@zash.se> | 2024-07-11 15:24:19 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2024-07-11 15:24:19 +0200 |
commit | bb278430cf13e3fbbdf0d36a5884c74a067e4a86 (patch) | |
tree | 3cb957e684cd52a6acdb0c081f3dfc9180401ad0 | |
parent | ca417ab7767b3ba8f62bdbdbd51f306f159375ea (diff) | |
download | prosody-bb278430cf13e3fbbdf0d36a5884c74a067e4a86.tar.gz prosody-bb278430cf13e3fbbdf0d36a5884c74a067e4a86.zip |
util.xtemplate: Fix error on applying each() to zero stanzas
Backport of 1f93e4f78c53
-rw-r--r-- | teal-src/util/xtemplate.tl | 5 | ||||
-rw-r--r-- | util/xtemplate.lua | 3 |
2 files changed, 6 insertions, 2 deletions
diff --git a/teal-src/util/xtemplate.tl b/teal-src/util/xtemplate.tl index b3bdc400..cdc913bf 100644 --- a/teal-src/util/xtemplate.tl +++ b/teal-src/util/xtemplate.tl @@ -46,7 +46,10 @@ local function render(template : string, root : st.stanza_t, escape : escape_t, if tmpl then tmpl = s_sub(tmpl, 2, -2); end if args then args = s_sub(args, 2, -2); end - if func == "each" and tmpl and st.is_stanza(value) then + if func == "each" and tmpl then + if not st.is_stanza(value) then + return ""; + end if not args then value, args = root, path; end local ns, name = s_match(args, "^(%b{})(.*)$"); if ns then ns = s_sub(ns, 2, -2); else name, ns = args, nil; end diff --git a/util/xtemplate.lua b/util/xtemplate.lua index 254c8af0..88baf1f7 100644 --- a/util/xtemplate.lua +++ b/util/xtemplate.lua @@ -31,7 +31,8 @@ local function render(template, root, escape, filters) if tmpl then tmpl = s_sub(tmpl, 2, -2); end if args then args = s_sub(args, 2, -2); end - if func == "each" and tmpl and st.is_stanza(value) then + if func == "each" and tmpl then + if not st.is_stanza(value) then return "" end if not args then value, args = root, path; end local ns, name = s_match(args, "^(%b{})(.*)$"); if ns then |