mirror of
https://github.com/Shopify/liquid.git
synced 2025-09-28 00:00:14 -04:00
Merge pull request #398 from Shopify/fix_order_of_constructor_initialize
Reorder constructor to avoid referencing uninitialized variable when environment contains a self-referencing proc
This commit is contained in:
commit
a8e63ff03d
@ -19,11 +19,12 @@ module Liquid
|
|||||||
SQUARE_BRACKETED = /\A\[(.*)\]\z/m
|
SQUARE_BRACKETED = /\A\[(.*)\]\z/m
|
||||||
|
|
||||||
def initialize(environments = {}, outer_scope = {}, registers = {}, rethrow_errors = false, resource_limits = {})
|
def initialize(environments = {}, outer_scope = {}, registers = {}, rethrow_errors = false, resource_limits = {})
|
||||||
@environments = [environments].flatten
|
@environments = [environments].flatten
|
||||||
@scopes = [(outer_scope || {})]
|
@scopes = [(outer_scope || {})]
|
||||||
@registers = registers
|
@registers = registers
|
||||||
@errors = []
|
@errors = []
|
||||||
@resource_limits = (resource_limits || {}).merge!({ :render_score_current => 0, :assign_score_current => 0 })
|
@resource_limits = (resource_limits || {}).merge!({ :render_score_current => 0, :assign_score_current => 0 })
|
||||||
|
@parsed_variables = Hash.new{ |cache, markup| cache[markup] = variable_parse(markup) }
|
||||||
squash_instance_assigns_with_environments
|
squash_instance_assigns_with_environments
|
||||||
|
|
||||||
if rethrow_errors
|
if rethrow_errors
|
||||||
@ -32,7 +33,6 @@ module Liquid
|
|||||||
|
|
||||||
@interrupts = []
|
@interrupts = []
|
||||||
@filters = []
|
@filters = []
|
||||||
@parsed_variables = Hash.new{ |cache, markup| cache[markup] = variable_parse(markup) }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def increment_used_resources(key, obj)
|
def increment_used_resources(key, obj)
|
||||||
|
@ -483,4 +483,12 @@ class ContextUnitTest < Test::Unit::TestCase
|
|||||||
assert_equal 1, mock_scan.calls.size
|
assert_equal 1, mock_scan.calls.size
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_context_initialization_with_a_proc_in_environment
|
||||||
|
contx = Context.new([:test => lambda { |c| c['poutine']}], {:test => :foo})
|
||||||
|
|
||||||
|
assert contx
|
||||||
|
assert_nil contx['poutine']
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
end # ContextTest
|
end # ContextTest
|
||||||
|
Loading…
x
Reference in New Issue
Block a user