Skip to content

Commit

Permalink
fix(template): allow null as a valid argument in helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
vvagaytsev committed Jul 12, 2023
1 parent 679ef3a commit 05d1dac
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions core/src/template-string/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,11 +476,13 @@ export function callHelperFunction({
const resolvedArgs: any[] = []

for (const arg of args) {
if (arg._error) {
// arg can be null here because some helpers allow nulls as valid args
if (arg && arg._error) {
return arg
}

if (arg && arg.resolved) {
// allow nulls as valid arg values
if (arg && arg.resolved !== undefined) {
resolvedArgs.push(arg.resolved)
} else {
resolvedArgs.push(arg)
Expand Down
14 changes: 14 additions & 0 deletions core/test/unit/src/template-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,20 @@ describe("resolveTemplateString", async () => {
})
})

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

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

context("slice", () => {
it("allows numeric indices", () => {
const res = resolveTemplateString("${slice(foo, 0, 3)}", new TestContext({ foo: "abcdef" }))
Expand Down

0 comments on commit 05d1dac

Please sign in to comment.