Strange handling of FALSE with include
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 11.9k
- Forks
- 1.5k
- Avg merge
- 17h 55m
- Merged PRs (30d)
- 3
Description
Inside a template
{% assign var1 = false %}
{% unless var1 %}
{% assign var1 = 'give var1 a value' %}
{% endunless %}
{% unless var2 %}
{% assign var2 = 'give var2 a value' %}
{% endunless %}
{{ var1 }} {{ var2 }}
The output is give var1 a value give var2 a value.
If there is a parent with
{% assign var1 = false %}
{% include 'second_template' %}
and then inside the second template
{% unless var1 %}
{% assign var1 = 'give var1 a value' %}
{% endunless %}
{% unless var2 %}
{% assign var2 = 'give var2 a value' %}
{% endunless %}
{{ var1 }} {{ var2 }}
The output is also give var1 a value give var2 a value.
But if you include like this
{% include 'second_template', var1: false %}
and then inside the second template again
{% unless var1 %}
{% assign var1 = 'give var1 a value' %}
{% endunless %}
{% unless var2 %}
{% assign var2 = 'give var2 a value' %}
{% endunless %}
{{ var1 }} {{ var2 }}
The output is false give var2 a value.
The odd thing is, that unless is still triggered, but false is not overwritten and just used as plain output. If this is meant as feature it should be like that for all variables, but for example an empty string can get overwritten if a test with if/unless fails.
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 reproducing the three include and unless examples from the issue and compare how direct assignments differ from include parameters. Trace the include variable-scope and assignment behavior, then add regression coverage for the reported false-value case and the existing empty-string behavior. Done means the intended handling is consistent and the examples have verified output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100