diff --git a/lib/haml/compiler/comment_compiler.rb b/lib/haml/compiler/comment_compiler.rb index 3695c51d..7fe2a469 100644 --- a/lib/haml/compiler/comment_compiler.rb +++ b/lib/haml/compiler/comment_compiler.rb @@ -14,7 +14,7 @@ module Haml def compile_html_comment(node, &block) if node.children.empty? - [:html, :comment, [:static, " #{node.value[:text]} "]] + [:html, :comment, compile_text(node)] else [:html, :comment, yield(node)] end @@ -28,12 +28,24 @@ module Haml content = if node.children.empty? - [:static, " #{node.value[:text]} "] + compile_text(node) else yield(node) end [:html, :condcomment, condition, content, node.value[:revealed]] end + + def compile_text(node) + text = + if node.value[:parse] + # Just always escaping the result for safety. We could respect + # escape_html, but I don't see any use case for it. + [:escape, true, [:dynamic, node.value[:text]]] + else + [:static, node.value[:text]] + end + [:multi, [:static, ' '], text, [:static, ' ']] + end end end end diff --git a/test/haml/engine/comment_test.rb b/test/haml/engine/comment_test.rb index 38431653..d4ba5267 100644 --- a/test/haml/engine/comment_test.rb +++ b/test/haml/engine/comment_test.rb @@ -6,6 +6,10 @@ describe Haml::Engine do assert_render(%Q|\n|, '/ comments') end + it 'renders intepolation' do + assert_render(%Q|\n|, '/ #{"comments"}') + end + it 'strips html comment ignoring around spcaes' do assert_render(%Q|\n|, '/ comments ') end @@ -61,6 +65,7 @@ describe Haml::Engine do world HAML end + it 'renders conditional comment' do assert_render(<<-HTML.unindent, <<-'HAML'.unindent)