mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-26 13:45:13 -07:00
Remove unused quirk allowing liquid tags to close a block it is nested in (#1284)
This commit is contained in:
@@ -29,6 +29,11 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def unknown_tag(tag, _params, _tokens)
|
def unknown_tag(tag, _params, _tokens)
|
||||||
|
Block.raise_unknown_tag(tag, block_name, block_delimiter, parse_context)
|
||||||
|
end
|
||||||
|
|
||||||
|
# @api private
|
||||||
|
def self.raise_unknown_tag(tag, block_name, block_delimiter, parse_context)
|
||||||
if tag == 'else'
|
if tag == 'else'
|
||||||
raise SyntaxError, parse_context.locale.t("errors.syntax.unexpected_else",
|
raise SyntaxError, parse_context.locale.t("errors.syntax.unexpected_else",
|
||||||
block_name: block_name)
|
block_name: block_name)
|
||||||
|
|||||||
@@ -54,21 +54,20 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
# @api private
|
# @api private
|
||||||
def self.unknown_tag_in_liquid_tag(end_tag_name, end_tag_markup)
|
def self.unknown_tag_in_liquid_tag(tag, parse_context)
|
||||||
yield end_tag_name, end_tag_markup
|
Block.raise_unknown_tag(tag, 'liquid', '%}', parse_context)
|
||||||
ensure
|
|
||||||
Usage.increment("liquid_tag_contains_outer_tag") unless $ERROR_INFO.is_a?(SyntaxError)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private def parse_liquid_tag(markup, parse_context, &block)
|
private def parse_liquid_tag(markup, parse_context)
|
||||||
liquid_tag_tokenizer = Tokenizer.new(markup, line_number: parse_context.line_number, for_liquid_tag: true)
|
liquid_tag_tokenizer = Tokenizer.new(markup, line_number: parse_context.line_number, for_liquid_tag: true)
|
||||||
parse_for_liquid_tag(liquid_tag_tokenizer, parse_context) do |end_tag_name, end_tag_markup|
|
parse_for_liquid_tag(liquid_tag_tokenizer, parse_context) do |end_tag_name, _end_tag_markup|
|
||||||
next unless end_tag_name
|
if end_tag_name
|
||||||
self.class.unknown_tag_in_liquid_tag(end_tag_name, end_tag_markup, &block)
|
BlockBody.unknown_tag_in_liquid_tag(end_tag_name, parse_context)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private def parse_for_document(tokenizer, parse_context, &block)
|
private def parse_for_document(tokenizer, parse_context)
|
||||||
while (token = tokenizer.shift)
|
while (token = tokenizer.shift)
|
||||||
next if token.empty?
|
next if token.empty?
|
||||||
case
|
case
|
||||||
@@ -87,7 +86,7 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
if tag_name == 'liquid'
|
if tag_name == 'liquid'
|
||||||
parse_liquid_tag(markup, parse_context, &block)
|
parse_liquid_tag(markup, parse_context)
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -82,15 +82,13 @@ class LiquidTagTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_nested_liquid_tag
|
def test_nested_liquid_tag
|
||||||
assert_usage_increment("liquid_tag_contains_outer_tag", times: 0) do
|
assert_template_result('good', <<~LIQUID)
|
||||||
assert_template_result('good', <<~LIQUID)
|
{%- if true %}
|
||||||
{%- if true %}
|
{%- liquid
|
||||||
{%- liquid
|
echo "good"
|
||||||
echo "good"
|
%}
|
||||||
%}
|
{%- endif -%}
|
||||||
{%- endif -%}
|
LIQUID
|
||||||
LIQUID
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_cannot_open_blocks_living_past_a_liquid_tag
|
def test_cannot_open_blocks_living_past_a_liquid_tag
|
||||||
@@ -102,14 +100,12 @@ class LiquidTagTest < Minitest::Test
|
|||||||
LIQUID
|
LIQUID
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_quirk_can_close_blocks_created_before_a_liquid_tag
|
def test_cannot_close_blocks_created_before_a_liquid_tag
|
||||||
assert_usage_increment("liquid_tag_contains_outer_tag") do
|
assert_match_syntax_error("syntax error (line 3): 'endif' is not a valid delimiter for liquid tags. use %}", <<~LIQUID)
|
||||||
assert_template_result("42", <<~LIQUID)
|
{%- if true -%}
|
||||||
{%- if true -%}
|
42
|
||||||
42
|
{%- liquid endif -%}
|
||||||
{%- liquid endif -%}
|
LIQUID
|
||||||
LIQUID
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_liquid_tag_in_raw
|
def test_liquid_tag_in_raw
|
||||||
|
|||||||
Reference in New Issue
Block a user