Shopify / Shopify/liquid

Unexpected Range Behaviors

Open
#1,890 2 comments 1 reaction 0 assignees View on GitHub

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:

  1. 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
  1. Both strict and lax mode do not support range in a variable outside of for loop. This works in LiquidJs and DotLiquid
assert_equal '12345',
     Liquid::Template.parse('{{(1..5)}}', error_mode: :strict).render
  1. 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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.