From 77084930e9569bd8a8b7ecf644f40e4ed1fbe0e0 Mon Sep 17 00:00:00 2001 From: Dylan Thacker-Smith Date: Tue, 15 Sep 2020 10:35:18 -0400 Subject: [PATCH] Bring back silencing of errors in blank nodes for backwards compatibility (#1292) --- lib/liquid/block_body.rb | 5 ++++- test/integration/error_handling_test.rb | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/liquid/block_body.rb b/lib/liquid/block_body.rb index e2ebf7a..3c2f8e7 100644 --- a/lib/liquid/block_body.rb +++ b/lib/liquid/block_body.rb @@ -77,7 +77,10 @@ module Liquid raise rescue ::StandardError => e line_number = node.is_a?(String) ? nil : node.line_number - output << context.handle_error(e, line_number) + error_message = context.handle_error(e, line_number) + if node.instance_of?(Variable) || !node.blank? # conditional for backwards compatibility + output << error_message + end end private def parse_liquid_tag(markup, parse_context) diff --git a/test/integration/error_handling_test.rb b/test/integration/error_handling_test.rb index c6463cc..2e59df2 100644 --- a/test/integration/error_handling_test.rb +++ b/test/integration/error_handling_test.rb @@ -261,4 +261,12 @@ class ErrorHandlingTest < Minitest::Test assert_equal("Argument error:\nLiquid error (product line 1): argument error", page) assert_equal("product", template.errors.first.template_name) end + + def test_bug_compatible_silencing_of_errors_in_blank_nodes + output = Liquid::Template.parse("{% assign x = 0 %}{% if 1 < '2' %}not blank{% assign x = 3 %}{% endif %}{{ x }}").render + assert_equal("Liquid error: comparison of Integer with String failed0", output) + + output = Liquid::Template.parse("{% assign x = 0 %}{% if 1 < '2' %}{% assign x = 3 %}{% endif %}{{ x }}").render + assert_equal("0", output) + end end