Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/liquid/tags/case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def parse_strict2_when(markup, body)
parser = @parse_context.new_parser(markup)

loop do
expr = safe_parse_expression(parser)
expr = Condition.parse_expression(parse_context, parser.expression, safe: true)
block = Condition.new(@left, '==', expr)
block.attach(body)
@blocks << block
Expand Down
20 changes: 20 additions & 0 deletions test/unit/tags/case_tag_unit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,26 @@ def test_case_when_with_or
end
end

def test_case_when_empty
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm only adding a test for empty as blank requires activesupport in order to render as we expect, however both have parity with lax

template = <<~LIQUID
{%- case x -%}
{%- when 2 or empty -%}
2 or empty
{%- else -%}
not 2 or empty
{%- endcase -%}
LIQUID

with_error_modes(:lax, :strict, :strict2) do
assert_template_result("2 or empty", template, { 'x' => 2 })
assert_template_result("2 or empty", template, { 'x' => {} })
assert_template_result("2 or empty", template, { 'x' => [] })
assert_template_result("not 2 or empty", template, { 'x' => { 'a' => 'b' } })
assert_template_result("not 2 or empty", template, { 'x' => ['a'] })
assert_template_result("not 2 or empty", template, { 'x' => 4 })
end
end

def test_case_with_invalid_expression
template = <<~LIQUID
{%- case foo=>bar -%}
Expand Down
Loading