Skip to content

Commit

Permalink
fix error on empty :javascript and :css filter blocks (#986)
Browse files Browse the repository at this point in the history
Fixes #985.
  • Loading branch information
wjordan authored and k0kubun committed Mar 10, 2018
1 parent 9856684 commit c32fa3c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/haml/filters.rb
Expand Up @@ -182,7 +182,7 @@ def compile(compiler, text)
return
end

rendered = Haml::Helpers::find_and_preserve(filter.render_with_options(text, compiler.options), compiler.options[:preserve])
rendered = Haml::Helpers::find_and_preserve(filter.render_with_options(text.to_s, compiler.options), compiler.options[:preserve])
push_text("#{rendered.rstrip}\n")
end
end
Expand Down
12 changes: 12 additions & 0 deletions test/filters_test.rb
Expand Up @@ -185,6 +185,12 @@ class JavascriptFilterTest < Haml::TestCase
refute_match('//<![CDATA[', out)
refute_match('//]]>', out)
end

test "should emit tag on empty block" do
html = "<script>\n \n</script>\n"
haml = ":javascript"
assert_equal(html, render(haml))
end
end

class CSSFilterTest < Haml::TestCase
Expand Down Expand Up @@ -224,6 +230,12 @@ class CSSFilterTest < Haml::TestCase
refute_match('<![CDATA[', out)
refute_match(']]>', out)
end

test "should emit tag on empty block" do
html = "<style>\n \n</style>\n"
haml = ":css"
assert_equal(html, render(haml))
end
end

class CDATAFilterTest < Haml::TestCase
Expand Down

0 comments on commit c32fa3c

Please sign in to comment.