diff --git a/chrome/content/zotero/xpcom/utilities_internal.js b/chrome/content/zotero/xpcom/utilities_internal.js index decfd8cfd5..de9c2b45a0 100644 --- a/chrome/content/zotero/xpcom/utilities_internal.js +++ b/chrome/content/zotero/xpcom/utilities_internal.js @@ -2228,7 +2228,15 @@ Zotero.Utilities.Internal = { } if (['if', 'elseif'].includes(operator)) { if (!level.executed) { - level.condition = level.parentCondition && (args[2] ? vars[args[0]].toLowerCase() == args[2].toLowerCase() : !!vars[args[0]]); + level.condition = level.parentCondition && ( + args[2] + ? vars[args[0]].toLowerCase() == args[2].toLowerCase() + : ( + Array.isArray(vars[args[0]]) + ? !!vars[args[0]].length + : !!vars[args[0]] + ) + ); level.executed = level.condition; } else { diff --git a/test/tests/utilities_internalTest.js b/test/tests/utilities_internalTest.js index f8122036f9..1e5028b4ad 100644 --- a/test/tests/utilities_internalTest.js +++ b/test/tests/utilities_internalTest.js @@ -529,11 +529,14 @@ describe("Zotero.Utilities.Internal", function () { v1: '1', v2: (pars) => pars.a1 + pars.a2 + pars.a3, v3: () => undefined, + ar1: [], + ar2: [1, 2] }; - var template = `{{ v1}}{{v2 a1= 1 a2 =' 2' a3 = "3 "}}{{v3}}{{v4}}`; + var template = `{{ v1}}{{v2 a1= 1 a2 =' 2' a3 = "3 "}}{{v3}}{{v4}}{{if ar1}}ar1{{endif}}{{if ar2}}{{ar2}}{{endif}}`; var html = Zotero.Utilities.Internal.generateHTMLFromTemplate(template, vars); - assert.equal(html, '11 23 '); + assert.equal(html, '11 23 1,2'); }); + it("should support nested 'if' statements", function () { var vars = { v1: '1',