Unexpected Range Behaviors
Open
Nobody has claimed this yet.
Bug Report
- Dominant language
- Ruby
- Stars
- 11.9k
- Forks
- 1.5k
- Avg merge
- 17h 55m
- Merged PRs (30d)
- 3
Description
There are two main issues being reported here:
- Strict mode vs not does not give the same behavior in simple ranges, where strict mode works and lax does not. In this example, there are extra spaces in the range.
assert_equal '12345',
Liquid::Template.parse('{%for item in (1 .. 5)%}{{item}}{%endfor%}').render
- Both strict and lax mode do not support range in a variable outside of
forloop. This works in LiquidJs and DotLiquid
assert_equal '12345',
Liquid::Template.parse('{{(1..5)}}', error_mode: :strict).render
- Variables with double dots trip the regex method of parsing ranges
def test_range_dotted_variable
nativedata = { 'paths' => { '..' => 1, '...' => 5 } }
assert_equal '1 5',
Liquid::Template.parse('{{ paths[".."] }} {{ paths["..."] }}', error_mode: :strict).render(nativedata)
assert_equal '12345',
Liquid::Template.parse('{%for item in (1..paths["..."]) %}{{item}}{%endfor%}', error_mode: :strict).render(nativedata)
assert_equal '12345',
Liquid::Template.parse('{%for item in (paths[".."]..paths["..."]) %}{{item}}{%endfor%}', error_mode: :strict).render(nativedata)
end
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 examples through Liquid::Template.parse, comparing strict and lax modes and range expressions inside and outside for loops. Trace the range parsing and variable lookup entry points implicated by those examples; done means all shown assertions produce the expected output without breaking dotted variable names.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100