mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-19 10:52:48 -07:00
Fix case where a variable name is falsy
This commit is contained in:
@@ -83,7 +83,7 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def render(context)
|
def render(context)
|
||||||
return ''.freeze unless @name
|
return ''.freeze if @name.nil?
|
||||||
@filters.inject(context.evaluate(@name)) do |output, (filter_name, filter_args, filter_kwargs)|
|
@filters.inject(context.evaluate(@name)) do |output, (filter_name, filter_args, filter_kwargs)|
|
||||||
filter_args = evaluate_filter_expressions(context, filter_args, filter_kwargs)
|
filter_args = evaluate_filter_expressions(context, filter_args, filter_kwargs)
|
||||||
output = context.invoke(filter_name, output, *filter_args)
|
output = context.invoke(filter_name, output, *filter_args)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ class IfElseTagTest < Minitest::Test
|
|||||||
assert_template_result(' this text should go into the output ',
|
assert_template_result(' this text should go into the output ',
|
||||||
' {% if true %} this text should go into the output {% endif %} ')
|
' {% if true %} this text should go into the output {% endif %} ')
|
||||||
assert_template_result(' you rock ?','{% if false %} you suck {% endif %} {% if true %} you rock {% endif %}?')
|
assert_template_result(' you rock ?','{% if false %} you suck {% endif %} {% if true %} you rock {% endif %}?')
|
||||||
|
assert_template_result(' NO ','{% assign v = false %}{% if v %} YES {% else %} NO {% endif %}')
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_if_else
|
def test_if_else
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ class VariableTest < Minitest::Test
|
|||||||
|
|
||||||
def test_false_renders_as_false
|
def test_false_renders_as_false
|
||||||
assert_equal 'false', Template.parse("{{ foo }}").render!('foo' => false)
|
assert_equal 'false', Template.parse("{{ foo }}").render!('foo' => false)
|
||||||
|
assert_equal 'false', Template.parse("{{ false }}").render!
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_preset_assigns
|
def test_preset_assigns
|
||||||
|
|||||||
Reference in New Issue
Block a user