Skip to content

Commit

Permalink
fix(template): ignore errors in skipped ternary clause
Browse files Browse the repository at this point in the history
Fixes #2678
  • Loading branch information
edvald authored and thsig committed Nov 25, 2021
1 parent a8806b5 commit 8b2eca5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
7 changes: 0 additions & 7 deletions core/src/template-string/parser.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,6 @@ ConditionalExpression
if (test && test._error) {
return test
}
if (consequent && consequent._error) {
return consequent
}
if (alternate && alternate._error) {
return alternate
}
return getValue(test) ? consequent : alternate
}
/ LogicalORExpression
Expand Down
5 changes: 5 additions & 0 deletions core/test/unit/src/template-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,11 @@ describe("resolveTemplateString", async () => {
expect(res).to.equal(true)
})

it("should ignore errors in a value not returned by a ternary", async () => {
const res = resolveTemplateString("${var.foo ? replace(var.foo, ' ', ',') : null}", new TestContext({ var: {} }))
expect(res).to.equal(null)
})

it("should handle a ternary expression with an object as a test", async () => {
const res = resolveTemplateString("${a ? a.value : b}", new TestContext({ a: { value: true }, b: false }))
expect(res).to.equal(true)
Expand Down

0 comments on commit 8b2eca5

Please sign in to comment.