Unhandled syntax error: "else if" is parsed as "else"
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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