Skip to content

Align if conditions with Ruby Liquid for missing values#612

Open
ahmedadamio wants to merge 19 commits intocobalt-org:masterfrom
mashry-hq:feat/filter-chain-in-conditions
Open

Align if conditions with Ruby Liquid for missing values#612
ahmedadamio wants to merge 19 commits intocobalt-org:masterfrom
mashry-hq:feat/filter-chain-in-conditions

Conversation

@ahmedadamio
Copy link
Copy Markdown

@ahmedadamio ahmedadamio commented Mar 29, 2026

Ruby Liquid treats missing variables in condition expressions as nil, and still applies filters on them. liquid-rust did not fully match that behavior.

Before this PR in liquid-rust:
{% if missing | upcase %} skipped filter application and evaluated as falsy
{% if missing == nil %} and {% if missing | upcase == "" %} could raise at runtime
unknown filters inside conditions could degrade into a generic parse error
This PR brings if / unless behavior closer to the Ruby Liquid implementation by:

treating missing values in conditions as nil
applying filters to missing values in condition paths
making binary comparisons use the same nil-tolerant evaluation as existence checks
preserving proper Unknown filter errors in conditions
Existing targeted tests continued to pass as expected. I re-ran:

cargo test -p liquid-lib if_block
cargo test -p liquid-lib assign
cargo fmt --all --check
Added / updated test coverage:

plain_existence_check_with_missing_value_is_falsy
filter_chain_existence_check_with_missing_value_applies_filters
missing_value_comparison_treats_missing_as_nil
missing_value_comparison_with_filters_applies_filters
unknown_filter_in_condition_reports_filter_error
This improves Shopify/Ruby Liquid compatibility and makes condition behavior more predictable for template authors.

  • [x ] Tests created for any new feature or regression tests for bugfixes.

@ahmedadamio ahmedadamio changed the title feat(if): Support filter chains in conditional expressions Align if conditions with Ruby Liquid for missing values Mar 29, 2026
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