mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-29 15:15:19 -07:00
Merge pull request #1680 from Shopify/recursively-parse-brackets
recursively parse brackets on variable lookup
This commit is contained in:
+1
-1
@@ -41,7 +41,7 @@ module Liquid
|
|||||||
AnyStartingTag = /#{TagStart}|#{VariableStart}/o
|
AnyStartingTag = /#{TagStart}|#{VariableStart}/o
|
||||||
PartialTemplateParser = /#{TagStart}.*?#{TagEnd}|#{VariableStart}.*?#{VariableIncompleteEnd}/om
|
PartialTemplateParser = /#{TagStart}.*?#{TagEnd}|#{VariableStart}.*?#{VariableIncompleteEnd}/om
|
||||||
TemplateParser = /(#{PartialTemplateParser}|#{AnyStartingTag})/om
|
TemplateParser = /(#{PartialTemplateParser}|#{AnyStartingTag})/om
|
||||||
VariableParser = /\[[^\]]+\]|#{VariableSegment}+\??/o
|
VariableParser = /\[(?:[^\[\]]+|\g<0>)*\]|#{VariableSegment}+\??/o
|
||||||
|
|
||||||
RAISE_EXCEPTION_LAMBDA = ->(_e) { raise }
|
RAISE_EXCEPTION_LAMBDA = ->(_e) { raise }
|
||||||
|
|
||||||
|
|||||||
@@ -135,4 +135,38 @@ class VariableTest < Minitest::Test
|
|||||||
def test_raw_value_variable
|
def test_raw_value_variable
|
||||||
assert_template_result('bar', '{{ [key] }}', { 'key' => 'foo', 'foo' => 'bar' })
|
assert_template_result('bar', '{{ [key] }}', { 'key' => 'foo', 'foo' => 'bar' })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_dynamic_find_var_with_drop
|
||||||
|
assert_template_result(
|
||||||
|
'bar',
|
||||||
|
'{{ [list[settings.zero]] }}',
|
||||||
|
{
|
||||||
|
'list' => ['foo'],
|
||||||
|
'settings' => SettingsDrop.new("zero" => 0),
|
||||||
|
'foo' => 'bar',
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
assert_template_result(
|
||||||
|
'foo',
|
||||||
|
'{{ [list[settings.zero]["foo"]] }}',
|
||||||
|
{
|
||||||
|
'list' => [{ 'foo' => 'bar' }],
|
||||||
|
'settings' => SettingsDrop.new("zero" => 0),
|
||||||
|
'bar' => 'foo',
|
||||||
|
}
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_double_nested_variable_lookup
|
||||||
|
assert_template_result(
|
||||||
|
'bar',
|
||||||
|
'{{ list[list[settings.zero]]["foo"] }}',
|
||||||
|
{
|
||||||
|
'list' => [1, { 'foo' => 'bar' }],
|
||||||
|
'settings' => SettingsDrop.new("zero" => 0),
|
||||||
|
'bar' => 'foo',
|
||||||
|
}
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -125,6 +125,17 @@ class ThingWithToLiquid
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class SettingsDrop < Liquid::Drop
|
||||||
|
def initialize(settings)
|
||||||
|
super()
|
||||||
|
@settings = settings
|
||||||
|
end
|
||||||
|
|
||||||
|
def liquid_method_missing(key)
|
||||||
|
@settings[key]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class IntegerDrop < Liquid::Drop
|
class IntegerDrop < Liquid::Drop
|
||||||
def initialize(value)
|
def initialize(value)
|
||||||
super()
|
super()
|
||||||
|
|||||||
Reference in New Issue
Block a user