mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-19 19:00:39 -07:00
Add error messages for missing variables when :strict
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
## 3.0.0 / not yet released / branch "master"
|
## 3.0.0 / not yet released / branch "master"
|
||||||
|
|
||||||
* ...
|
* ...
|
||||||
|
* Add error messages for missing variables when :strict, see #352 [Daniel Gaiottino]
|
||||||
* Fix broken rendering of variables which are equal to false, see #345 [Florian Weingarten, fw42]
|
* Fix broken rendering of variables which are equal to false, see #345 [Florian Weingarten, fw42]
|
||||||
* Remove ActionView template handler [Dylan Thacker-Smith, dylanahsmith]
|
* Remove ActionView template handler [Dylan Thacker-Smith, dylanahsmith]
|
||||||
* Freeze lots of string literals for new Ruby 2.1 optimization, see #297 [Florian Weingarten, fw42]
|
* Freeze lots of string literals for new Ruby 2.1 optimization, see #297 [Florian Weingarten, fw42]
|
||||||
|
|||||||
@@ -203,6 +203,7 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
scope ||= @environments.last || @scopes.last
|
scope ||= @environments.last || @scopes.last
|
||||||
|
handle_not_found(key) unless scope.has_key?(key)
|
||||||
variable ||= lookup_and_evaluate(scope, key)
|
variable ||= lookup_and_evaluate(scope, key)
|
||||||
|
|
||||||
variable = variable.to_liquid
|
variable = variable.to_liquid
|
||||||
@@ -252,6 +253,7 @@ module Liquid
|
|||||||
# No key was present with the desired value and it wasn't one of the directly supported
|
# 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
|
# keywords either. The only thing we got left is to return nil
|
||||||
else
|
else
|
||||||
|
handle_not_found(markup)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -281,6 +283,10 @@ module Liquid
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end # squash_instance_assigns_with_environments
|
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 # Context
|
||||||
|
|
||||||
end # Liquid
|
end # Liquid
|
||||||
|
|||||||
@@ -457,4 +457,22 @@ class ContextUnitTest < Test::Unit::TestCase
|
|||||||
assert_kind_of CategoryDrop, @context['category']
|
assert_kind_of CategoryDrop, @context['category']
|
||||||
assert_equal @context, @context['category'].context
|
assert_equal @context, @context['category'].context
|
||||||
end
|
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
|
end # ContextTest
|
||||||
|
|||||||
Reference in New Issue
Block a user