Align if conditions with Ruby Liquid for missing values#612
Open
ahmedadamio wants to merge 19 commits intocobalt-org:masterfrom
Open
Align if conditions with Ruby Liquid for missing values#612ahmedadamio wants to merge 19 commits intocobalt-org:masterfrom
ahmedadamio wants to merge 19 commits intocobalt-org:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 runtimeunknown 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.