From b53601100f8ef56946c765bfbf3bc69d3cb0986d Mon Sep 17 00:00:00 2001 From: Florian Weingarten Date: Tue, 2 Jul 2013 13:57:27 -0400 Subject: [PATCH] Make sure include tags are never blank --- lib/liquid/tags/include.rb | 4 ++++ test/liquid/blank_test.rb | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/liquid/tags/include.rb b/lib/liquid/tags/include.rb index e19c373..42eff17 100644 --- a/lib/liquid/tags/include.rb +++ b/lib/liquid/tags/include.rb @@ -38,6 +38,10 @@ module Liquid def parse(tokens) end + def blank? + false + end + def render(context) partial = load_cached_partial(context) variable = context[@variable_name || @template_name[1..-2]] diff --git a/test/liquid/blank_test.rb b/test/liquid/blank_test.rb index bcc7999..0817d91 100644 --- a/test/liquid/blank_test.rb +++ b/test/liquid/blank_test.rb @@ -1,5 +1,11 @@ require 'test_helper' +class BlankTestFileSystem + def read_template_file(template_path, context) + template_path + end +end + class BlankTest < Test::Unit::TestCase include Liquid N = 10 @@ -77,4 +83,11 @@ class BlankTest < Test::Unit::TestCase assert_template_result(" "*(N+1), wrap(' {{ "" }} ')) assert_template_result(" "*(N+1), wrap("{% assign foo = ' ' %}{{ foo }}")) end + + def test_include_is_blank + Liquid::Template.file_system = BlankTestFileSystem.new + assert_equal "foobar"*(N+1), Template.parse(wrap("{% include 'foobar' %}")).render() + assert_equal " foobar "*(N+1), Template.parse(wrap("{% include ' foobar ' %}")).render() + assert_equal " ", Template.parse(" {% include ' ' %} ").render() + end end