From b2a3210a271e8155d290f142708f24de54c98bb1 Mon Sep 17 00:00:00 2001 From: Ben Lipton Date: Fri, 15 Jul 2016 14:18:40 -0400 Subject: [PATCH] Fix double-adding tokens in raw tags The current logic for adding tokens in the raw tag has the potential to add to the body a substring of a token, and then the full token, resulting in doubled data. This happens when the token matches the FullTokenPossiblyInvalid regex, but does not contain the expected end tag. For example, this occurs when a template contains a string like "{% raw %}{{ {% test %} }}{% endraw %}", in which case the tokenizer produces "{{ {% test %}" as one of the tokens, and the template output is "{{ {{ {% test %} }}". --- lib/liquid/tags/raw.rb | 4 ++-- test/integration/tags/raw_tag_test.rb | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/liquid/tags/raw.rb b/lib/liquid/tags/raw.rb index 6b461bdb5..ce797541a 100644 --- a/lib/liquid/tags/raw.rb +++ b/lib/liquid/tags/raw.rb @@ -12,9 +12,9 @@ def initialize(tag_name, markup, parse_context) def parse(tokens) @body = '' while token = tokens.shift - if token =~ FullTokenPossiblyInvalid + if token =~ FullTokenPossiblyInvalid and block_delimiter == $2 @body << $1 if $1 != "".freeze - return if block_delimiter == $2 + return end @body << token unless token.empty? end diff --git a/test/integration/tags/raw_tag_test.rb b/test/integration/tags/raw_tag_test.rb index 634d052d1..d5ee6a767 100644 --- a/test/integration/tags/raw_tag_test.rb +++ b/test/integration/tags/raw_tag_test.rb @@ -23,6 +23,10 @@ def test_open_tag_in_raw assert_template_result ' Foobar {{ invalid 1', '{% raw %} Foobar {{ invalid {% endraw %}{{ 1 }}' end + def test_nested_tag_in_raw + assert_template_result '{{ {% test %} }}', '{% raw %}{{ {% test %} }}{% endraw %}' + end + def test_invalid_raw assert_match_syntax_error(/tag was never closed/, '{% raw %} foo') assert_match_syntax_error(/Valid syntax/, '{% raw } foo {% endraw %}')