Skip to content

Commit b7a0330

Browse files
committed
Render arguments should maintain correct precedence
1 parent d106eef commit b7a0330

File tree

3 files changed

+1064
-383
lines changed

3 files changed

+1064
-383
lines changed

lib/liquid.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ module Liquid
4040
QuotedString = /"[^"]*"|'[^']*'/
4141
QuotedFragment = /#{QuotedString}|(?:[^\s,\|'"]|#{QuotedString})+/o
4242
TagAttributes = /(\w[\w-]*)\s*\:\s*(#{QuotedFragment})/o
43+
ContextInheritance = /\.\.\./
4344
AnyStartingTag = /#{TagStart}|#{VariableStart}/o
4445
PartialTemplateParser = /#{TagStart}.*?#{TagEnd}|#{VariableStart}.*?#{VariableIncompleteEnd}/om
4546
TemplateParser = /(#{PartialTemplateParser}|#{AnyStartingTag})/om

lib/liquid/tags/render.rb

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ def for_loop?
4242
@is_for_loop
4343
end
4444

45-
def inherit_context?
46-
@inherit_context
47-
end
48-
4945
def render_to_output_buffer(context, output)
5046
render_tag(context, output)
5147
end
@@ -77,18 +73,18 @@ def render_tag(context, output)
7773
inner_context.partial = true
7874
end
7975

80-
if is_inline && inherit_context?
81-
context.scopes.each do |scope|
82-
scope.each do |key, value|
83-
inner_context[key] = value
76+
@attributes.each do |key, value|
77+
if key == "..." && is_inline
78+
context.scopes.each do |scope|
79+
scope.each do |k, v|
80+
inner_context[k] = v
81+
end
8482
end
83+
else
84+
inner_context[key] = context.evaluate(value)
8585
end
8686
end
8787

88-
@attributes.each do |key, value|
89-
inner_context[key] = context.evaluate(value)
90-
end
91-
9288
inner_context[context_variable_name] = var unless var.nil?
9389
inner_context['forloop'] = forloop if forloop
9490

@@ -129,19 +125,17 @@ def rigid_parse(markup)
129125
# optional comma
130126
p.consume?(:comma)
131127

132-
@inherit_context = false
133-
# ... inline snippets syntax
134-
if p.consume?(:dotdotdot)
135-
p.consume?(:comma)
136-
137-
@inherit_context = true
138-
end
139-
140128
@attributes = {}
141-
while p.look(:id)
142-
key = p.consume
143-
p.consume(:colon)
144-
@attributes[key] = safe_parse_expression(p)
129+
while p.look(:dotdotdot) || p.look(:id)
130+
if p.consume?(:dotdotdot)
131+
@attributes.delete("...")
132+
@attributes["..."] = true
133+
else
134+
key = p.consume
135+
p.consume(:colon)
136+
@attributes.delete(key)
137+
@attributes[key] = safe_parse_expression(p)
138+
end
145139
p.consume?(:comma) # optional comma
146140
end
147141

@@ -172,11 +166,16 @@ def lax_parse(markup)
172166
@variable_name_expr = variable_name ? parse_expression(variable_name) : nil
173167
@template_name_expr = parse_expression(template_name)
174168
@is_for_loop = (with_or_for == FOR)
175-
@inherit_context = markup.include?('...')
176169

177170
@attributes = {}
178-
markup.scan(TagAttributes) do |key, value|
179-
@attributes[key] = parse_expression(value)
171+
markup.scan(/(#{ContextInheritance})|#{TagAttributes.source}/) do |context_marker, key, value|
172+
if context_marker
173+
@attributes.delete("...")
174+
@attributes["..."] = true
175+
elsif key && value
176+
@attributes.delete(key)
177+
@attributes[key] = parse_expression(value)
178+
end
180179
end
181180
end
182181

0 commit comments

Comments
 (0)