From 36c0fba4e042af70ad0212b198d5c84e1817c4e6 Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Tue, 5 Nov 2019 17:43:14 -0500 Subject: [PATCH] Fix post-trim for the raw tag The added test did not pass before this commit. --- lib/liquid/tags/raw.rb | 5 ++++- test/integration/tags/raw_tag_test.rb | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/liquid/tags/raw.rb b/lib/liquid/tags/raw.rb index e4a78a8..80b3a1f 100644 --- a/lib/liquid/tags/raw.rb +++ b/lib/liquid/tags/raw.rb @@ -16,7 +16,10 @@ module Liquid while (token = tokens.shift) if token =~ FullTokenPossiblyInvalid @body << Regexp.last_match(1) if Regexp.last_match(1) != "" - return if block_delimiter == Regexp.last_match(2) + if block_delimiter == Regexp.last_match(2) + @parse_context.trim_whitespace = (token[-3] == WhitespaceControl) + return + end 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 b927ef0..284d6b6 100644 --- a/test/integration/tags/raw_tag_test.rb +++ b/test/integration/tags/raw_tag_test.rb @@ -14,6 +14,10 @@ class RawTagTest < Minitest::Test assert_template_result('{{ test }}', '{% raw %}{{ test }}{% endraw %}') end + def test_post_trim + assert_template_result('hi', "{% raw %}hi{% endraw -%}\n") + end + def test_open_tag_in_raw assert_template_result(' Foobar {% invalid ', '{% raw %} Foobar {% invalid {% endraw %}') assert_template_result(' Foobar invalid %} ', '{% raw %} Foobar invalid %} {% endraw %}')