Preserve literal semantics in strict2 case/when

Previously, strict2 case/when used `safe_parse_expression`
to parse when expressions causing `blank`/`empty` to be
treated as string literals (Expression::LITERALS maps 'empty' => ''),
rather than method literals

This caused unexpected behavior:

```
{%- case empty_obj -%}
{%- when empty -%}
  previously: doesn't render (empty_obj == '' is false)
  now: renders (empty_obj.empty? is true)
{%- endcase -%}
```

This commit instead calls `Condition.parse_expression`
with `safe: true`, which will correctly handle `blank`
and `empty`
This commit is contained in:
Julia Boutin
2025-11-28 15:51:48 -07:00
parent 32b50ecafe
commit fa27bfe6e0
2 changed files with 21 additions and 1 deletions
+1 -1
View File
@@ -118,7 +118,7 @@ module Liquid
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