Compare commits

...

1 Commits

Author SHA1 Message Date
Dylan Thacker-Smith
f0cc366cfc Fix missing freeze for array of static environments 2020-09-30 10:26:14 -04:00
2 changed files with 15 additions and 3 deletions

View File

@@ -18,15 +18,16 @@ module Liquid
attr_accessor :exception_renderer, :template_name, :partial, :global_filter, :strict_variables, :strict_filters
# rubocop:disable Metrics/ParameterLists
def self.build(environments: {}, outer_scope: {}, registers: {}, rethrow_errors: false, resource_limits: nil, static_environments: {})
def self.build(environments: {}, outer_scope: {}, registers: {}, rethrow_errors: false, resource_limits: nil, static_environments: [])
new(environments, outer_scope, registers, rethrow_errors, resource_limits, static_environments)
end
def initialize(environments = {}, outer_scope = {}, registers = {}, rethrow_errors = false, resource_limits = nil, static_environments = {})
def initialize(environments = {}, outer_scope = {}, registers = {}, rethrow_errors = false, resource_limits = nil, static_environments = [])
@environments = [environments]
@environments.flatten!
@static_environments = [static_environments].flat_map(&:freeze).freeze
static_environments = [static_environments] if static_environments.is_a?(Hash)
@static_environments = static_environments.map(&:freeze).freeze
@scopes = [(outer_scope || {})]
@registers = registers
@errors = []

View File

@@ -492,6 +492,17 @@ class ContextTest < Minitest::Test
assert_equal('static', context['unshadowed'])
end
def test_static_environments_are_frozen
context = Context.build(
static_environments: [{
'lazy' => -> { 1 }
}],
)
assert_raises(FrozenError) do
context['lazy']
end
end
def test_apply_global_filter_when_no_global_filter_exist
context = Context.new
assert_equal('hi', context.apply_global_filter('hi'))