Allow commas to separate for
tag attributes
#1658
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
There are multiple tags that use Liquid::TagAttributes to scan for attributes, but the only one that has strict parsing is the
for
tag and that strict parsing doesn't allow commas as separators as we typically use in other tags for tag attributes.For example, the
render
tag documentation for passing variables to a snippet demonstrates this with{% render 'filename', variable: value %}
. Based on what I see in the dawn theme, it looks like this is our preferred style (e.g. we have{% render 'card-collection', card_collection: block.settings.collection , media_aspect_ratio: section.settings.image_ratio, columns: columns %}
)In contrast, trying to use the same style in the
for
tag (e.g.{% for i in array, limit: 4, offset: 2 %}...{% endfor %}
) would be a syntax error in strict parsing mode, requiring only a space to be used as a separate (e.g.{% for i in array limit: 4 offset: 2 %}...{% endfor %}
).Solution
Update Liquid::For#strict_parse to optionally allow commas to separate tag attributes.
Note that the
for
tag also allows areversed
option to be specified, but it is different from a tag attribute in that it isn't given a value and is expected to precede any tag attributes. Given this, I decided it didn't need to also allow a comma to precede it.