diff --git a/lib/liquid/block.rb b/lib/liquid/block.rb index d9547c78..00c59b2d 100644 --- a/lib/liquid/block.rb +++ b/lib/liquid/block.rb @@ -26,12 +26,12 @@ module Liquid end def unknown_tag(tag, _params, _tokens) - case tag - when 'else'.freeze + if tag == 'else'.freeze raise SyntaxError.new(parse_context.locale.t("errors.syntax.unexpected_else".freeze, block_name: block_name)) - when 'end'.freeze + elsif tag.start_with?('end'.freeze) raise SyntaxError.new(parse_context.locale.t("errors.syntax.invalid_delimiter".freeze, + tag: tag, block_name: block_name, block_delimiter: block_delimiter)) else diff --git a/lib/liquid/locales/en.yml b/lib/liquid/locales/en.yml index 9a259bf1..48b3b1d8 100644 --- a/lib/liquid/locales/en.yml +++ b/lib/liquid/locales/en.yml @@ -14,7 +14,7 @@ if: "Syntax Error in tag 'if' - Valid syntax: if [expression]" include: "Error in tag 'include' - Valid syntax: include '[template]' (with|for) [object|collection]" unknown_tag: "Unknown tag '%{tag}'" - invalid_delimiter: "'end' is not a valid delimiter for %{block_name} tags. use %{block_delimiter}" + invalid_delimiter: "'%{tag}' is not a valid delimiter for %{block_name} tags. use %{block_delimiter}" unexpected_else: "%{block_name} tag does not expect 'else' tag" unexpected_outer_tag: "Unexpected outer '%{tag}' tag" tag_termination: "Tag '%{token}' was not properly terminated with regexp: %{tag_end}" diff --git a/test/integration/block_test.rb b/test/integration/block_test.rb new file mode 100644 index 00000000..08245301 --- /dev/null +++ b/test/integration/block_test.rb @@ -0,0 +1,12 @@ +require 'test_helper' + +class BlockTest < Minitest::Test + include Liquid + + def test_unexpected_end_tag + exc = assert_raises(SyntaxError) do + Template.parse("{% if true %}{% endunless %}") + end + assert_equal exc.message, "Liquid syntax error: 'endunless' is not a valid delimiter for if tags. use endif" + end +end