Skip to content

Commit

Permalink
Allow commas to separate for tag attributes (#1658)
Browse files Browse the repository at this point in the history
For consistency with tags like the `render` tag, where we actually
prefer to use commas to separate attributes
  • Loading branch information
dylanahsmith authored Nov 29, 2022
1 parent 9ccbf64 commit c2c6cb2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/liquid/tags/for.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ def strict_parse(markup)
@name = "#{@variable_name}-#{collection_name}"
@reversed = p.id?('reversed')

while p.look(:id) && p.look(:colon, 1)
while p.look(:comma) || p.look(:id)
p.consume?(:comma)
unless (attribute = p.id?('limit') || p.id?('offset'))
raise SyntaxError, options[:locale].t("errors.syntax.for_invalid_attribute")
end
p.consume
p.consume(:colon)
set_attribute(attribute, p.expression)
end
p.consume(:end_of_string)
Expand Down
1 change: 1 addition & 0 deletions test/integration/tags/for_tag_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def test_limiting
assert_template_result('1234', '{%for i in array limit:4 %}{{ i }}{%endfor%}', assigns)
assert_template_result('3456', '{%for i in array limit:4 offset:2 %}{{ i }}{%endfor%}', assigns)
assert_template_result('3456', '{%for i in array limit: 4 offset: 2 %}{{ i }}{%endfor%}', assigns)
assert_template_result('3456', '{%for i in array, limit: 4, offset: 2 %}{{ i }}{%endfor%}', assigns)
end

def test_limiting_with_invalid_limit
Expand Down

0 comments on commit c2c6cb2

Please sign in to comment.