mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-20 11:20:41 -07:00
This reverts commit 27ead517ee.
This commit is contained in:
+3
-7
@@ -34,7 +34,7 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
# @api private
|
# @api private
|
||||||
def self.raise_unknown_tag(tag, block_name, block_delimiter, parse_context, supports_end_tag = true)
|
def self.raise_unknown_tag(tag, block_name, block_delimiter, parse_context)
|
||||||
if tag == 'else'
|
if tag == 'else'
|
||||||
raise SyntaxError, parse_context.locale.t(
|
raise SyntaxError, parse_context.locale.t(
|
||||||
"errors.syntax.unexpected_else",
|
"errors.syntax.unexpected_else",
|
||||||
@@ -42,7 +42,7 @@ module Liquid
|
|||||||
)
|
)
|
||||||
elsif tag.start_with?('end')
|
elsif tag.start_with?('end')
|
||||||
raise SyntaxError, parse_context.locale.t(
|
raise SyntaxError, parse_context.locale.t(
|
||||||
supports_end_tag ? "errors.syntax.invalid_delimiter" : "errors.syntax.invalid_delimiter_no_end",
|
"errors.syntax.invalid_delimiter",
|
||||||
tag: tag,
|
tag: tag,
|
||||||
block_name: block_name,
|
block_name: block_name,
|
||||||
block_delimiter: block_delimiter,
|
block_delimiter: block_delimiter,
|
||||||
@@ -64,10 +64,6 @@ module Liquid
|
|||||||
@block_delimiter ||= "end#{block_name}"
|
@block_delimiter ||= "end#{block_name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def supports_end_tag?
|
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# @api public
|
# @api public
|
||||||
@@ -85,7 +81,7 @@ module Liquid
|
|||||||
body.parse(tokens, parse_context) do |end_tag_name, end_tag_params|
|
body.parse(tokens, parse_context) do |end_tag_name, end_tag_params|
|
||||||
@blank &&= body.blank?
|
@blank &&= body.blank?
|
||||||
|
|
||||||
return false if end_tag_name == block_delimiter || (supports_end_tag? && end_tag_name == 'end')
|
return false if end_tag_name == block_delimiter
|
||||||
raise_tag_never_closed(block_name) unless end_tag_name
|
raise_tag_never_closed(block_name) unless end_tag_name
|
||||||
|
|
||||||
# this tag is not registered with the system
|
# this tag is not registered with the system
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ module Liquid
|
|||||||
|
|
||||||
# @api private
|
# @api private
|
||||||
def self.unknown_tag_in_liquid_tag(tag, parse_context)
|
def self.unknown_tag_in_liquid_tag(tag, parse_context)
|
||||||
Block.raise_unknown_tag(tag, 'liquid', '%}', parse_context, false)
|
Block.raise_unknown_tag(tag, 'liquid', '%}', parse_context)
|
||||||
end
|
end
|
||||||
|
|
||||||
# @api private
|
# @api private
|
||||||
|
|||||||
@@ -14,8 +14,7 @@
|
|||||||
if: "Syntax Error in tag 'if' - Valid syntax: if [expression]"
|
if: "Syntax Error in tag 'if' - Valid syntax: if [expression]"
|
||||||
include: "Error in tag 'include' - Valid syntax: include '[template]' (with|for) [object|collection]"
|
include: "Error in tag 'include' - Valid syntax: include '[template]' (with|for) [object|collection]"
|
||||||
inline_comment_invalid: "Syntax error in tag '#' - Each line of comments must be prefixed by the '#' character"
|
inline_comment_invalid: "Syntax error in tag '#' - Each line of comments must be prefixed by the '#' character"
|
||||||
invalid_delimiter: "'%{tag}' is not a valid delimiter for %{block_name} tags. use end or %{block_delimiter}"
|
invalid_delimiter: "'%{tag}' is not a valid delimiter for %{block_name} tags. use %{block_delimiter}"
|
||||||
invalid_delimiter_no_end: "'%{tag}' is not a valid delimiter for %{block_name} tags. use %{block_delimiter}"
|
|
||||||
render: "Syntax error in tag 'render' - Template name must be a quoted string"
|
render: "Syntax error in tag 'render' - Template name must be a quoted string"
|
||||||
table_row: "Syntax Error in 'table_row loop' - Valid syntax: table_row [item] in [collection] cols=3"
|
table_row: "Syntax Error in 'table_row loop' - Valid syntax: table_row [item] in [collection] cols=3"
|
||||||
tag_never_closed: "'%{block_name}' tag was never closed"
|
tag_never_closed: "'%{block_name}' tag was never closed"
|
||||||
|
|||||||
@@ -22,10 +22,6 @@ module Liquid
|
|||||||
def unknown_tag(_tag, _markup, _tokens)
|
def unknown_tag(_tag, _markup, _tokens)
|
||||||
end
|
end
|
||||||
|
|
||||||
def supports_end_tag?
|
|
||||||
false
|
|
||||||
end
|
|
||||||
|
|
||||||
def blank?
|
def blank?
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -22,10 +22,6 @@ module Liquid
|
|||||||
ensure_valid_markup(tag_name, markup, parse_context)
|
ensure_valid_markup(tag_name, markup, parse_context)
|
||||||
end
|
end
|
||||||
|
|
||||||
def supports_end_tag?
|
|
||||||
false
|
|
||||||
end
|
|
||||||
|
|
||||||
def parse(tokens)
|
def parse(tokens)
|
||||||
@body = +''
|
@body = +''
|
||||||
while (token = tokens.shift)
|
while (token = tokens.shift)
|
||||||
|
|||||||
@@ -5,31 +5,9 @@ require 'test_helper'
|
|||||||
class BlockTest < Minitest::Test
|
class BlockTest < Minitest::Test
|
||||||
include Liquid
|
include Liquid
|
||||||
|
|
||||||
def test_simple_end_tag
|
|
||||||
assert_template_result('you rock', '{% if true %}you rock{% end %}')
|
|
||||||
assert_template_result('you rock', '{% if true %}{% unless false %}you rock{% end %}{% end %}')
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_unexpected_end_tag
|
def test_unexpected_end_tag
|
||||||
source = '{% if true %}{% endunless %}'
|
source = '{% if true %}{% endunless %}'
|
||||||
assert_match_syntax_error("Liquid syntax error (line 1): 'endunless' is not a valid delimiter for if tags. use end or endif", source)
|
assert_match_syntax_error("Liquid syntax error (line 1): 'endunless' is not a valid delimiter for if tags. use endif", source)
|
||||||
end
|
|
||||||
|
|
||||||
def test_end_closes_closest_open_tag
|
|
||||||
source = '{% if true %}{% unless true %}{% end %}{% endunless %}'
|
|
||||||
assert_match_syntax_error("Liquid syntax error (line 1): 'endunless' is not a valid delimiter for if tags. use end or endif", source)
|
|
||||||
end
|
|
||||||
|
|
||||||
# comments are special and can't be closed by `end`
|
|
||||||
def test_unexpected_end_tag_comment
|
|
||||||
source = '{% comment %}{% end %}'
|
|
||||||
assert_match_syntax_error("Liquid syntax error (line 1): 'comment' tag was never closed", source)
|
|
||||||
end
|
|
||||||
|
|
||||||
# raw is special and can't be closed by `end`
|
|
||||||
def test_unexpected_end_tag_raw
|
|
||||||
source = '{% raw %}{% end %}'
|
|
||||||
assert_match_syntax_error("Liquid syntax error (line 1): 'raw' tag was never closed", source)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_with_custom_tag
|
def test_with_custom_tag
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ class IfElseTagTest < Minitest::Test
|
|||||||
' {% if true %} this text should go into the output {% endif %} ',
|
' {% if true %} this text should go into the output {% endif %} ',
|
||||||
)
|
)
|
||||||
assert_template_result(' you rock ?', '{% if false %} you suck {% endif %} {% if true %} you rock {% endif %}?')
|
assert_template_result(' you rock ?', '{% if false %} you suck {% endif %} {% if true %} you rock {% endif %}?')
|
||||||
assert_template_result(' you rock ?', '{% if false %} you suck {% endif %} {% if true %} you rock {% end %}?')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_literal_comparisons
|
def test_literal_comparisons
|
||||||
|
|||||||
@@ -106,11 +106,6 @@ class LiquidTagTest < Minitest::Test
|
|||||||
42
|
42
|
||||||
{%- liquid endif -%}
|
{%- liquid endif -%}
|
||||||
LIQUID
|
LIQUID
|
||||||
assert_match_syntax_error("syntax error (line 3): 'end' is not a valid delimiter for liquid tags. use %}", <<~LIQUID)
|
|
||||||
{%- if true -%}
|
|
||||||
42
|
|
||||||
{%- liquid end -%}
|
|
||||||
LIQUID
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_liquid_tag_in_raw
|
def test_liquid_tag_in_raw
|
||||||
@@ -128,15 +123,6 @@ class LiquidTagTest < Minitest::Test
|
|||||||
endif
|
endif
|
||||||
-%}
|
-%}
|
||||||
LIQUID
|
LIQUID
|
||||||
|
|
||||||
assert_template_result('good', <<~LIQUID)
|
|
||||||
{%- liquid
|
|
||||||
liquid
|
|
||||||
if true
|
|
||||||
echo "good"
|
|
||||||
end
|
|
||||||
-%}
|
|
||||||
LIQUID
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_nested_liquid_tags_on_same_line
|
def test_nested_liquid_tags_on_same_line
|
||||||
|
|||||||
@@ -10,10 +10,6 @@ class RawTagTest < Minitest::Test
|
|||||||
'{% comment %} test {% endcomment %}',
|
'{% comment %} test {% endcomment %}',
|
||||||
'{% raw %}{% comment %} test {% endcomment %}{% endraw %}',
|
'{% raw %}{% comment %} test {% endcomment %}{% endraw %}',
|
||||||
)
|
)
|
||||||
assert_template_result(
|
|
||||||
'',
|
|
||||||
'{% comment %} {% if true %}{% end %} {% endcomment %}',
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_output_in_raw
|
def test_output_in_raw
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ class StandardTagTest < Minitest::Test
|
|||||||
assert_template_result('', '{%comment%}{%blabla%}{%endcomment%}')
|
assert_template_result('', '{%comment%}{%blabla%}{%endcomment%}')
|
||||||
assert_template_result('', '{% comment %}{% blabla %}{% endcomment %}')
|
assert_template_result('', '{% comment %}{% blabla %}{% endcomment %}')
|
||||||
assert_template_result('', '{%comment%}{% endif %}{%endcomment%}')
|
assert_template_result('', '{%comment%}{% endif %}{%endcomment%}')
|
||||||
assert_template_result('', '{%comment%}{% end %}{%endcomment%}')
|
|
||||||
assert_template_result('', '{% comment %}{% endwhatever %}{% endcomment %}')
|
assert_template_result('', '{% comment %}{% endwhatever %}{% endcomment %}')
|
||||||
assert_template_result('', '{% comment %}{% raw %} {{%%%%}} }} { {% endcomment %} {% comment {% endraw %} {% endcomment %}')
|
assert_template_result('', '{% comment %}{% raw %} {{%%%%}} }} { {% endcomment %} {% comment {% endraw %} {% endcomment %}')
|
||||||
assert_template_result('', '{% comment %}{% " %}{% endcomment %}')
|
assert_template_result('', '{% comment %}{% " %}{% endcomment %}')
|
||||||
|
|||||||
Reference in New Issue
Block a user