Skip to content

Conversation

@dejmedus
Copy link
Contributor

@dejmedus dejmedus commented Nov 28, 2025

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

This caused unexpected behaviour:

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

This PR instead calls Condition.parse_expression with safe: true, which will correctly handle blank/empty

Example example

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`
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

@dejmedus dejmedus marked this pull request as ready for review November 29, 2025 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant