From 8909c9f27abd73ace797151064ae253110293124 Mon Sep 17 00:00:00 2001 From: Florian Weingarten Date: Tue, 8 Jul 2014 14:47:39 +0000 Subject: [PATCH 1/2] add regression tests for #377 --- test/integration/context_test.rb | 10 ++++++++++ test/integration/tags/include_tag_test.rb | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/test/integration/context_test.rb b/test/integration/context_test.rb index 83bb43e..0f4255a 100644 --- a/test/integration/context_test.rb +++ b/test/integration/context_test.rb @@ -20,4 +20,14 @@ class ContextTest < Test::Unit::TestCase assert_equal 'Global test', Template.parse("{{'test' | notice }}").render! assert_equal 'Local test', Template.parse("{{'test' | notice }}").render!({}, :filters => [local]) end + + def test_has_key_will_not_add_an_error_for_missing_keys + Template.error_mode = :strict + + context = Context.new + + context.has_key?('unknown') + + assert_empty context.errors + end end diff --git a/test/integration/tags/include_tag_test.rb b/test/integration/tags/include_tag_test.rb index b79cfd7..eca109f 100644 --- a/test/integration/tags/include_tag_test.rb +++ b/test/integration/tags/include_tag_test.rb @@ -205,4 +205,12 @@ class IncludeTagTest < Test::Unit::TestCase Liquid::Template.tags['include'] = original_tag end end + + def test_does_not_add_error_in_strict_mode_for_missing_variable + Liquid::Template.file_system = TestFileSystem.new + + a = Liquid::Template.parse(' {% include "nested_template" %}') + a.render! + assert_empty a.errors + end end # IncludeTagTest From 0ac3ec783496301610700be65e18c9be0fb9a2a5 Mon Sep 17 00:00:00 2001 From: Florian Weingarten Date: Tue, 8 Jul 2014 14:48:19 +0000 Subject: [PATCH 2/2] Revert "Merge pull request #352 from gaiottino/master" This reverts commit 553b0926ae28103475fd66e6637af855a81ddb0e, reversing changes made to 628ab3dc6a702d87340a6fdd9715d9ef54fab786. --- History.md | 1 - lib/liquid/context.rb | 6 ------ test/unit/context_unit_test.rb | 18 ------------------ 3 files changed, 25 deletions(-) diff --git a/History.md b/History.md index 3f78fa1..e56b3c5 100644 --- a/History.md +++ b/History.md @@ -3,7 +3,6 @@ ## 3.0.0 / not yet released / branch "master" * ... -* Add error messages for missing variables when :strict, see #352 [Daniel Gaiottino] * Properly set context rethrow_errors on render! #349 [Thierry Joyal, tjoyal] * Fix broken rendering of variables which are equal to false, see #345 [Florian Weingarten, fw42] * Remove ActionView template handler [Dylan Thacker-Smith, dylanahsmith] diff --git a/lib/liquid/context.rb b/lib/liquid/context.rb index 6c58bfb..a35dcf2 100644 --- a/lib/liquid/context.rb +++ b/lib/liquid/context.rb @@ -205,7 +205,6 @@ module Liquid end scope ||= @environments.last || @scopes.last - handle_not_found(key) unless scope.has_key?(key) variable ||= lookup_and_evaluate(scope, key) variable = variable.to_liquid @@ -255,7 +254,6 @@ module Liquid # No key was present with the desired value and it wasn't one of the directly supported # keywords either. The only thing we got left is to return nil else - handle_not_found(markup) return nil end @@ -285,10 +283,6 @@ module Liquid end end end # squash_instance_assigns_with_environments - - def handle_not_found(variable) - @errors << "Variable {{#{variable}}} not found" if Template.error_mode == :strict - end end # Context end # Liquid diff --git a/test/unit/context_unit_test.rb b/test/unit/context_unit_test.rb index 6d61dd9..8f4d6ed 100644 --- a/test/unit/context_unit_test.rb +++ b/test/unit/context_unit_test.rb @@ -457,22 +457,4 @@ class ContextUnitTest < Test::Unit::TestCase assert_kind_of CategoryDrop, @context['category'] assert_equal @context, @context['category'].context end - - def test_strict_variables_not_found - with_error_mode(:strict) do - @context['does_not_exist'] - assert(@context.errors.length == 1) - assert_equal(@context.errors[0], 'Variable {{does_not_exist}} not found') - end - end - - def test_strict_nested_variables_not_found - with_error_mode(:strict) do - @context['hash'] = {'this' => 'exists'} - @context['hash.does_not_exist'] - assert(@context.errors.length == 1) - assert_equal(@context.errors[0], 'Variable {{hash.does_not_exist}} not found') - end - end - end # ContextTest