Haml: Produces broken syntax for certain calls inside attribute interpolation

Created on 3 May 2017  路  3Comments  路  Source: haml/haml

Here's the reproduction

puts Haml::Engine.new(%{%a(data-foo="#{render 'foobar',foo: bar}")}).precompiled.gsub(';', "\n")

_the following has been re-indented for readability, notice that the second line produces invalid code ("#{render 'foobar')_

_hamlout.buffer << ("<a".freeze)
_haml_attribute_compiler1 = ("#{render 'foobar')
case (_haml_attribute_compiler1)
when Hash
  _hamlout.buffer << ((_hamlout.attributes({ "data-foo".freeze => _haml_attribute_compiler1 }, nil)).to_s)

when true
  _hamlout.buffer << (" data-foo".freeze)

when false, nil
else
  _hamlout.buffer << (" data-foo='".freeze)

  _hamlout.buffer << (::Haml::Helpers.html_escape((_haml_attribute_compiler1)))

  _hamlout.buffer << ("'".freeze)

end
_haml_attribute_compiler2 = (bar}")
case (_haml_attribute_compiler2)
when Hash
  _hamlout.buffer << ((_hamlout.attributes({ "foo".freeze => _haml_attribute_compiler2 }, nil)).to_s)

when true
  _hamlout.buffer << (" foo".freeze)

when false, nil
else
  _hamlout.buffer << (" foo='".freeze)

  _hamlout.buffer << (::Haml::Helpers.html_escape((_haml_attribute_compiler2)))

  _hamlout.buffer << ("'".freeze)

end
_hamlout.buffer << ("></a>\n".freeze)

Most helpful comment

Yes, just released 5.0.1 gem including the patch for this issue.

All 3 comments

Thank you for reporting. But this is essentially the same as https://github.com/haml/haml/issues/917 and already fixed on master branch. Please wait for new release.

@amatsuda Could you ship a new release?

Yes, just released 5.0.1 gem including the patch for this issue.

Was this page helpful?
0 / 5 - 0 ratings