Skip to content

Commit

Permalink
fix: case/when array equality, #673
Browse files Browse the repository at this point in the history
  • Loading branch information
Yang Jun committed Apr 28, 2024
1 parent dd9bbc5 commit c3f1ab9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/tags/case.ts
@@ -1,4 +1,5 @@
import { ValueToken, Liquid, toValue, evalToken, Value, Emitter, TagToken, TopLevelToken, Context, Template, Tag, ParseStream } from '..'
import { equals } from '../render'

export default class extends Tag {
value: Value
Expand Down Expand Up @@ -58,7 +59,7 @@ export default class extends Tag {
for (const branch of this.branches) {
for (const valueToken of branch.values) {
const value = yield evalToken(valueToken, ctx, ctx.opts.lenientIf)
if (target === value) {
if (equals(target, value)) {
yield r.renderTemplates(branch.templates, ctx, emitter)
branchHit = true
break
Expand Down
13 changes: 13 additions & 0 deletions test/integration/tags/case.spec.ts
Expand Up @@ -119,4 +119,17 @@ describe('tags/case', function () {
'{%- endcase %}', {})
expect(result).toEqual('show this')
})
it('should apply value equal for arrays', () => {
const engine = new Liquid()
const result = engine.parseAndRenderSync(`
{%- assign x = "a,b,c" | split: "," %}
{%- assign y = "a,b,c" | split: "," %}
{% case x %}{% when y %}TRUE{% else %}FALSE{% endcase %}
{% if x == y %}TRUE{% else %}FALSE{% endif %}
`)
expect(result).toEqual(`
TRUE
TRUE
`)
})
})

0 comments on commit c3f1ab9

Please sign in to comment.