mirror of
https://github.com/kemko/liquid.git
synced 2026-01-01 15:55:40 +03:00
Fix missing freeze for array of static environments
This commit is contained in:
@@ -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 = []
|
||||
|
||||
@@ -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'))
|
||||
|
||||
Reference in New Issue
Block a user