Shopify / Shopify/liquid

elsif inside else does not raise errors when parsing

Open
#1,652 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
11.9k
Forks
1.5k
Avg merge
17h 55m
Merged PRs (30d)
3

Description

{% assign randomNumber = first_name | size | modulo: 3 | plus: 1 %}
{% if randomNumber == 1 %}
Test
{% else %}
{% elsif randomNumber == 2 %}
Test 2
{% else %}
Test 3
{% endif %} 

In the following example, the user added an elsif inside an else block, whcih should be considered invalid.
However, when this block runs it doesn't return anything.

Liquid::Template.parse(stage.body, error_mode: :strict) --> works without any error when it should.
When rendering the result above, fails to run this block.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the supplied template with Liquid::Template.parse(..., error_mode: :strict) and confirm that the invalid elsif inside else is accepted. Trace the parser handling for else and elsif, then add a regression test in the relevant parser or error-mode test suite. Done means strict parsing raises an error for this structure and valid conditional branches still parse.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.