Fix template condition evaluating to true for empty string from function

Fixes #2529
This commit is contained in:
Martynas Bagdonas 2022-04-11 12:21:23 +07:00
parent be0b0a7151
commit 2af7275968
2 changed files with 14 additions and 4 deletions

View file

@ -528,13 +528,14 @@ describe("Zotero.Utilities.Internal", function () {
var vars = {
v1: '1',
v2: (pars) => pars.a1 + pars.a2 + pars.a3,
v3: () => undefined,
v3: () => '',
v5: () => 'something',
ar1: [],
ar2: [1, 2]
};
var template = `{{ v1}}{{v2 a1= 1 a2 =' 2' a3 = "3 "}}{{v3}}{{v4}}{{if ar1}}ar1{{endif}}{{if ar2}}{{ar2}}{{endif}}`;
var template = `{{ v1}}{{v2 a1= 1 a2 =' 2' a3 = "3 "}}{{v3}}{{v4}}{{if ar1}}ar1{{endif}}{{if ar2}}{{ar2}}{{endif}}{{if v5}}yes{{endif}}{{if v3}}no{{endif}}`;
var html = Zotero.Utilities.Internal.generateHTMLFromTemplate(template, vars);
assert.equal(html, '11 23 1,2');
assert.equal(html, '11 23 1,2yes');
});
it("should support nested 'if' statements", function () {