Add strict2_parse to increment and decrement tags#2067
Add strict2_parse to increment and decrement tags#2067aswamy wants to merge 1 commit intostrict2-assign-capturefrom
Conversation
b6bff03 to
3f70d61
Compare
| def strict2_parse(markup) | ||
| stripped = markup.strip | ||
| return @variable_name = stripped if stripped.empty? | ||
|
|
||
| p = @parse_context.new_parser(stripped) | ||
| @variable_name = p.consume(:id) | ||
| p.consume(:end_of_string) | ||
| end |
There was a problem hiding this comment.
i thought of merging the code between increment and decrement since they share so much, but didn't see it with other similar tags like case and if so i just kept it verbose
There was a problem hiding this comment.
Seems fair to leave them separate. I do have a question.
The guard return @variable_name = stripped if stripped.empty? - I think we want to remove it because in other tags like capture if we don't find a variable name we raise a syntax error through p.consume(:id)
There was a problem hiding this comment.
Hmm yeah i think that's fair. I looked at how lax mode handles {% increment %} (without a variable name) and apparently it's allowed. Internally, it looks like it's creating an empty-string variable that can be accessed via self[""]. Ill rewrite this into a valid variable name. Good catch!
3f70d61 to
5365de4
Compare
Both tags previously accepted any string as a variable name via `markup.strip`. Now they use `parse_with_selected_parser` and validate the variable name with `p.consume(:id)` in strict2 mode. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5365de4 to
c990360
Compare
Note
Stacked on Shopify/liquid#2065 (assign/capture strict2_parse)
Summary
Adds
strict2_parsetoIncrementandDecrementtags. Both tags previously accepted any string as a variable name viamarkup.strip— no Parser validation was performed in any mode.Changes:
include ParserSwitchingand useparse_with_selected_parserlax_parse: preserves the originalmarkup.stripbehaviorstrict_parse: delegates tolax_parsestrict2_parse: validates the variable name viap.consume(:id)+p.consume(:end_of_string)This means
{% increment foo bar %}and{% decrement 11aa %}are now rejected in strict2 mode.Tophat
bundle install bundle exec irb -r liquid🤖 Generated with Claude Code