Shopify / Shopify/liquid

parse_for_liquid_tag errors without line numbers

Open
#1,734 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

While adding some nested liquid tag test cases to the golden liquid test suite, I was getting errors like this:

  1) Error:
Golden::liquid.golden.liquid_tag#test_0001_bare liquid tag in liquid tag:
NoMethodError: undefined method `-' for nil:NilClass

            parse_context.line_number -= 1
                                      ^
    /home/james/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/bundler/gems/liquid-5e92b3a89a11/lib/liquid/block_body.rb:50:in `parse_for_liquid_tag'
    /home/james/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/bundler/gems/liquid-5e92b3a89a11/lib/liquid/block_body.rb:111:in `parse_liquid_tag'
    /home/james/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/bundler/gems/liquid-5e92b3a89a11/lib/liquid/block_body.rb:145:in `parse_for_document'
    /home/james/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/bundler/gems/liquid-5e92b3a89a11/lib/liquid/block_body.rb:29:in `parse'
    /home/james/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/bundler/gems/liquid-5e92b3a89a11/lib/liquid/document.rb:55:in `parse_body'
    /home/james/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/bundler/gems/liquid-5e92b3a89a11/lib/liquid/document.rb:23:in `parse'
    /home/james/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/bundler/gems/liquid-5e92b3a89a11/lib/liquid/document.rb:7:in `parse'
    /home/james/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/bundler/gems/liquid-5e92b3a89a11/lib/liquid/template.rb:111:in `parse'
    /home/james/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/bundler/gems/liquid-5e92b3a89a11/lib/liquid/template.rb:97:in `parse'
    golden_liquid.rb:25:in `block (5 levels) in <main>'

Adding line_numbers: true to Liquid::Template.parse solved the problem.

This is can be reproduced with the following:

require 'liquid'

template = <<~LIQUID
{%- liquid
    liquid
    echo 'foo'
-%}
LIQUID

Liquid::Template.parse(template).render!()

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 with lib/liquid/block_body.rb at parse_for_liquid_tag and follow how Liquid::Template.parse initializes parsing context line numbers. Run the minimal nested liquid-tag reproduction with and without line_numbers: true. Done means the reproduction no longer raises NoMethodError when line numbers are not enabled, while preserving line-number behavior when they are.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.