Skip to content

Commit

Permalink
fix(template): allow empty string as a valid arg of isEmpty helper
Browse files Browse the repository at this point in the history
test: empty strings
  • Loading branch information
vvagaytsev committed Jul 12, 2023
1 parent 05d1dac commit 66458a9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion core/src/template-string/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ const helperFunctionSpecs: TemplateHelperFunction[] = [
name: "isEmpty",
description: "Returns true if the given value is an empty string, object, array, null or undefined.",
arguments: {
value: joi.alternatives(joi.object(), joi.array(), joi.string()).allow(null).description("The value to check."),
value: joi
.alternatives(joi.object(), joi.array(), joi.string().allow(""))
.allow(null)
.description("The value to check."),
},
outputSchema: joi.boolean(),
exampleArguments: [
Expand Down
12 changes: 12 additions & 0 deletions core/test/unit/src/template-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,18 @@ describe("resolveTemplateString", async () => {
expect(res).to.be.true
})
})

context("allows empty strings", () => {
it("resolves an empty string as 'true'", () => {
const res = resolveTemplateString("${isEmpty('')}", new TestContext({}))
expect(res).to.be.true
})

it("resolves a reference to an empty string as 'true'", () => {
const res = resolveTemplateString("${isEmpty(a)}", new TestContext({ a: "" }))
expect(res).to.be.true
})
})
})

context("slice", () => {
Expand Down

0 comments on commit 66458a9

Please sign in to comment.