diff --git a/lib/liquid/tokenizer.rb b/lib/liquid/tokenizer.rb index 8b331d93c..41a70c131 100644 --- a/lib/liquid/tokenizer.rb +++ b/lib/liquid/tokenizer.rb @@ -9,6 +9,7 @@ class Tokenizer TAG_END = /%\}/ TAG_OR_VARIABLE_START = /\{[\{\%]/ NEWLINE = /\n/ + RAW_TAG_END = /-?\s*endraw\s*-?%\}/ OPEN_CURLEY = "{".ord CLOSE_CURLEY = "}".ord @@ -116,6 +117,11 @@ def next_variable_token byte_a = byte_b = @ss.scan_byte + # The second opening brace can start a tag, e.g. {{% endraw %}}. + if byte_a == PERCENTAGE && @ss.match?(RAW_TAG_END) + return next_tag_token_with_start(start) + end + while byte_b byte_a = @ss.scan_byte while byte_a && byte_a != CLOSE_CURLEY && byte_a != OPEN_CURLEY diff --git a/test/integration/tags/raw_tag_test.rb b/test/integration/tags/raw_tag_test.rb index 2ca43d3b2..501072c4b 100644 --- a/test/integration/tags/raw_tag_test.rb +++ b/test/integration/tags/raw_tag_test.rb @@ -36,4 +36,10 @@ def test_invalid_raw assert_match_syntax_error(/Valid syntax/, '{% raw } foo {% endraw %}') assert_match_syntax_error(/Valid syntax/, '{% raw } foo %}{% endraw %}') end + + def test_endraw_after_variable_start_with_trailing_brace + assert_template_result('%{}x', '{%raw%}%{{%endraw%}}{%raw%}x{%endraw%}') + assert_template_result('{}}after', '{% raw %}{{% endraw %}}}after') + assert_template_result('{x', '{% raw %}{{%- endraw -%} {{ "x" }}') + end end