You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I believe I have found a bug: liquid-rust seems to equate false and nil.
My reasons for believing this is a bug are as follows:
The observed behavior differs from that of Shopify's gem.
The observed behavior surprises me.
The observed behavior is inconsistent (as the code below demonstrates).
I've included Ruby and Rust sample code along with their outputs. I apologize for the long MWEs, but I thought clarity was more important than brevity in this case.
Also, please note that the examples below use copied and pasted templates between Ruby and Rust to ensure consistency; I haven't even touched the template indentation to match both languages' styles.
Shopify (Ruby, using gem liquid version 5.5.1)
require"liquid"deffalse_firstraw_template= \
"{% if x == true -%} if: true {%- elsif x == false -%} if: false {%- elsif x == nil -%} if: nil {%- else -%} if: else {%- endif -%} ; {% case x -%} {%- when true -%} case: true {%- when false -%} case: false {%- when nil -%} case: nil {%- else -%} case: else {%- endcase %}"template=Liquid::Template.parse(raw_template)puts"=== Comparison order: true, false, nil ==="puts"[true] #{template.render('x'=>true)}"puts"[false] #{template.render('x'=>false)}"puts"[nil] #{template.render('x'=>nil)}"putsenddefnil_firstraw_template= \
"{% if x == true -%} if: true {%- elsif x == nil -%} if: nil {%- elsif x == false -%} if: false {%- else -%} if: else {%- endif -%} ; {% case x -%} {%- when true -%} case: true {%- when nil -%} case: nil {%- when false -%} case: false {%- else -%} case: else {%- endcase %}"template=Liquid::Template.parse(raw_template)puts"=== Comparison order: true, nil, false ==="puts"[true] #{template.render('x'=>true)}"puts"[false] #{template.render('x'=>false)}"puts"[nil] #{template.render('x'=>nil)}"putsendfalse_firstnil_first
I have an optional Boolean value and need to distinguish Some(true), Some(false), and None.
Workaround
I map the value to a string literal before passing it to liquid::object!, and then I perform string comparison in my template, e.g. "nil" instead of nil.
The text was updated successfully, but these errors were encountered:
liquid-rust version: 0.26.9
rust version: rustc 1.82.0 (f6e511eec 2024-10-15)
OS: Debian 12 (bookworm)
I believe I have found a bug:
liquid-rust
seems to equatefalse
andnil
.My reasons for believing this is a bug are as follows:
I've included Ruby and Rust sample code along with their outputs. I apologize for the long MWEs, but I thought clarity was more important than brevity in this case.
Also, please note that the examples below use copied and pasted templates between Ruby and Rust to ensure consistency; I haven't even touched the template indentation to match both languages' styles.
Shopify (Ruby, using gem
liquid
version 5.5.1)Ruby output
Rust (using
liquid-rust
version 0.26.9):Rust output
Expected output
Use case
I have an optional Boolean value and need to distinguish
Some(true)
,Some(false)
, andNone
.Workaround
I map the value to a string literal before passing it to
liquid::object!
, and then I perform string comparison in my template, e.g."nil"
instead ofnil
.The text was updated successfully, but these errors were encountered: