From e6ed804ca56d6bcc818e439bee372cd5d8a379c3 Mon Sep 17 00:00:00 2001 From: Justin Li Date: Mon, 8 Apr 2019 18:43:09 -0400 Subject: [PATCH] Fix line number tracking after a non-empty blank token --- lib/liquid/block_body.rb | 6 +++--- test/integration/tags/liquid_tag_test.rb | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/liquid/block_body.rb b/lib/liquid/block_body.rb index 5f86545..4861bca 100644 --- a/lib/liquid/block_body.rb +++ b/lib/liquid/block_body.rb @@ -27,11 +27,11 @@ module Liquid private def parse_for_liquid_tag(tokenizer, parse_context) while token = tokenizer.shift case - when token.empty? - # pass + when token.empty? || token =~ WhitespaceOrNothing + # pass, but assign line_number below, since it could change even when + # the token is empty else unless token =~ LiquidTagToken - next if token =~ WhitespaceOrNothing # line isn't empty but didn't match tag syntax, yield and let the # caller raise a syntax error return yield token, token diff --git a/test/integration/tags/liquid_tag_test.rb b/test/integration/tags/liquid_tag_test.rb index 56ca712..d4be128 100644 --- a/test/integration/tags/liquid_tag_test.rb +++ b/test/integration/tags/liquid_tag_test.rb @@ -74,6 +74,11 @@ class LiquidTagTest < Minitest::Test LIQUID end + def test_line_number_is_correct_after_a_blank_token + assert_match_syntax_error("syntax error (line 3): Unknown tag 'error'", "{% liquid echo ''\n\n error %}") + assert_match_syntax_error("syntax error (line 3): Unknown tag 'error'", "{% liquid echo ''\n \n error %}") + end + def test_cannot_open_blocks_living_past_a_liquid_tag assert_match_syntax_error("syntax error (line 3): 'if' tag was never closed", <<~LIQUID) {%- liquid