Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/liquid/tokenizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions test/integration/tags/raw_tag_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading