Fix interpolation in comments

Fix #1107
This commit is contained in:
Takashi Kokubun 2022-10-28 22:26:08 -07:00
parent 8610dc1824
commit 06920a2634
No known key found for this signature in database
GPG Key ID: 6FFC433B12EE23DD
2 changed files with 19 additions and 2 deletions

View File

@ -14,7 +14,7 @@ module Haml
def compile_html_comment(node, &block) def compile_html_comment(node, &block)
if node.children.empty? if node.children.empty?
[:html, :comment, [:static, " #{node.value[:text]} "]] [:html, :comment, compile_text(node)]
else else
[:html, :comment, yield(node)] [:html, :comment, yield(node)]
end end
@ -28,12 +28,24 @@ module Haml
content = content =
if node.children.empty? if node.children.empty?
[:static, " #{node.value[:text]} "] compile_text(node)
else else
yield(node) yield(node)
end end
[:html, :condcomment, condition, content, node.value[:revealed]] [:html, :condcomment, condition, content, node.value[:revealed]]
end 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 end
end end

View File

@ -6,6 +6,10 @@ describe Haml::Engine do
assert_render(%Q|<!-- comments -->\n|, '/ comments') assert_render(%Q|<!-- comments -->\n|, '/ comments')
end end
it 'renders intepolation' do
assert_render(%Q|<!-- comments -->\n|, '/ #{"comments"}')
end
it 'strips html comment ignoring around spcaes' do it 'strips html comment ignoring around spcaes' do
assert_render(%Q|<!-- comments -->\n|, '/ comments ') assert_render(%Q|<!-- comments -->\n|, '/ comments ')
end end
@ -61,6 +65,7 @@ describe Haml::Engine do
world world
HAML HAML
end end
it 'renders conditional comment' do it 'renders conditional comment' do
assert_render(<<-HTML.unindent, <<-'HAML'.unindent) assert_render(<<-HTML.unindent, <<-'HAML'.unindent)
<!--[if lt IE 9]> <!--[if lt IE 9]>