Shopify / Shopify/liquid

Unhandled syntax error: "else if" is parsed as "else"

Open
#899 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

The following template has invalid syntax:

{% if false %}
  1
{% else if false %}
  2
{% else %}
  3
{% endif %}

The else if should be elsif, but instead of a SyntaxError being raised, the template is parsed without error and the else if acts as an else. Thus, the above example will always produce 2. This else if should fail to parse since the else has a condition (relevant code).

This can be confusing to end-users since the template is successfully parsed, leading them to believe the template is valid.

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 reading the conditional-tag parsing logic in lib/liquid/tags/if.rb around line 54. Verify how an else token with a condition is handled, then confirm that the provided template raises SyntaxError instead of rendering 2; done means invalid else conditions are rejected.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.