Skip to content

Commit

Permalink
handle undef comparison to blank street not printing warnings to stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Feb 2, 2024
1 parent c1a5ac8 commit 4b755b1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/Template/Liquid/Condition.pm
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ sub _equal { # XXX - Pray we don't have a recursive data structure...
my $ref_l = ref $l;
return !1 if $ref_l ne ref $r;
if (!$ref_l) {
if(!defined $l or !defined $r) {
return !1;
}
return
!!(grep {defined} $l, $r)
? (grep {m[\D]o || m[^$]} $l, $r)
Expand Down
18 changes: 15 additions & 3 deletions t/0200_tags/02006_if.t
Original file line number Diff line number Diff line change
Expand Up @@ -322,23 +322,35 @@ INPUT
Nope
EXPECTED
is( Template::Liquid->parse(
<<'INPUT')->render(foo => "", bar => undef), <<'EXPECTED', 'Check "" == 5');
<<'INPUT')->render(foo => "", bar => undef), <<'EXPECTED', 'Check "" != undef');
{% if foo == bar %}Yep.{% else %}Nope{% endif %}
INPUT
Nope
EXPECTED
is( Template::Liquid->parse(
<<'INPUT')->render(foo => "", bar => undef), <<'EXPECTED', 'Check "" == 5');
<<'INPUT')->render(foo => "", bar => undef), <<'EXPECTED', 'Check if ""');
{% if foo %}Yep.{% else %}Nope{% endif %}
INPUT
Nope
EXPECTED
is( Template::Liquid->parse(
<<'INPUT')->render(foo => "", bar => undef), <<'EXPECTED', 'Check "" == 5');
<<'INPUT')->render(foo => "", bar => undef), <<'EXPECTED', 'Check if undef');
{% if bar %}Yep.{% else %}Nope{% endif %}
INPUT
Nope
EXPECTED
is( Template::Liquid->parse(
<<'INPUT')->render(foo => "", bar => undef), <<'EXPECTED', 'Check undef == ""');
{% if mobile == "" %}BLANKMOBILE{% else %}NOTBLANK{% endif %}
INPUT
NOTBLANK
EXPECTED
is( Template::Liquid->parse(
<<'INPUT')->render(foo => "", bar => undef), <<'EXPECTED', 'Check undef == ""');
{% unless mobile %}BLANKMOBILE{% else %}NOTBLANK{% endunless %}
INPUT
BLANKMOBILE
EXPECTED


# I'm finished
Expand Down

0 comments on commit 4b755b1

Please sign in to comment.