From b8e7e2d9467b17ca786e6fb422e9579dd178de76 Mon Sep 17 00:00:00 2001 From: Francisco Soto Date: Fri, 18 Aug 2023 14:43:36 -0700 Subject: [PATCH] fix: case should allow multiple values separated by or This is supported by Shopify liquid. --- src/tags/case.ts | 7 ++++++- test/integration/tags/case.spec.ts | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/tags/case.ts b/src/tags/case.ts index b55df24655..23564d3a85 100644 --- a/src/tags/case.ts +++ b/src/tags/case.ts @@ -17,7 +17,12 @@ export default class extends Tag { const values: ValueToken[] = [] while (!token.tokenizer.end()) { values.push(token.tokenizer.readValueOrThrow()) - token.tokenizer.readTo(',') + token.tokenizer.skipBlank() + if (token.tokenizer.peek() === ',') { + token.tokenizer.readTo(',') + } else { + token.tokenizer.readTo('or') + } } this.branches.push({ values, diff --git a/test/integration/tags/case.spec.ts b/test/integration/tags/case.spec.ts index d15d452cb1..3312eb800a 100644 --- a/test/integration/tags/case.spec.ts +++ b/test/integration/tags/case.spec.ts @@ -75,4 +75,20 @@ describe('tags/case', function () { const html = await liquid.parseAndRender(src) return expect(html).toBe('firstsecond') }) + it('should support case with multiple values separated by or', async function () { + const src = '{% case 3 %}' + + '{% when 1 or 2 or 3 %}1 or 2 or 3' + + '{% else %}not 1 or 2 or 3' + + '{%endcase%}' + const html = await liquid.parseAndRender(src) + return expect(html).toBe('1 or 2 or 3') + }) + it('should support case with multiple strings separated by or', async function () { + const src = '{% case "or" %}' + + '{% when "and" or "or" %}and or or' + + '{% else %}not and or or' + + '{%endcase%}' + const html = await liquid.parseAndRender(src) + return expect(html).toBe('and or or') + }) })