Repository: haml/haml

Issue #917: Haml::InvalidAttributeNameError with dynamic arguments
Created: 2017-05-01T06:57:38Z
When running something like this:
- base_url = "http://www.google.com"
%iframe#test{src: "#{File.join base_url, '/abc/'}"}

I get the following error :
 Haml::InvalidAttributeNameError:
            Invalid attribute name '/abc/' was rendered
          # /Users/cdrapier/.gem/ruby/2.3.1/gems/haml-5.0.0/lib/haml/attribute_builder.rb:100:in `block in verify_attribute_names!'
          # /Users/cdrapier/.gem/ruby/2.3.1/gems/haml-5.0.0/lib/haml/attribute_builder.rb:98:in `each'
          # /Users/cdrapier/.gem/ruby/2.3.1/gems/haml-5.0.0/lib/haml/attribute_builder.rb:98:in `verify_attribute_names!'
          # /Users/cdrapier/.gem/ruby/2.3.1/gems/haml-5.0.0/lib/haml/attribute_compiler.rb:63:in `compile'
          # /Users/cdrapier/.gem/ruby/2.3.1/gems/haml-5.0.0/lib/haml/compiler.rb:111:in `compile_tag'
          # /Users/cdrapier/.gem/ruby/2.3.1/gems/haml-5.0.0/lib/haml/compiler.rb:28:in `compile'
          # /Users/cdrapier/.gem/ruby/2.3.1/gems/haml-5.0.0/lib/haml/compiler.rb:30:in `block (2 levels) in compile'
          # /Users/cdrapier/.gem/ruby/2.3.1/gems/haml-5.0.0/lib/haml/compiler.rb:30:in `each'
          # /Users/cdrapier/.gem/ruby/2.3.1/gems/haml-5.0.0/lib/haml/compiler.rb:30:in `block in compile'
          # /Users/cdrapier/.gem/ruby/2.3.1/gems/haml-5.0.0/lib/haml/compiler.rb:40:in `compile_root'
          # /Users/cdrapier/.gem/ruby/2.3.1/gems/haml-5.0.0/lib/haml/compiler.rb:30:in `compile'
          # /Users/cdrapier/.gem/ruby/2.3.1/gems/haml-5.0.0/lib/haml/compiler.rb:21:in `call'
          # /Users/cdrapier/.gem/ruby/2.3.1/gems/temple-0.8.0/lib/temple/engine.rb:50:in `block in call'
          # /Users/cdrapier/.gem/ruby/2.3.1/gems/temple-0.8.0/lib/temple/engine.rb:50:in `each'
          # /Users/cdrapier/.gem/ruby/2.3.1/gems/temple-0.8.0/lib/temple/engine.rb:50:in `inject'
          # /Users/cdrapier/.gem/ruby/2.3.1/gems/temple-0.8.0/lib/temple/engine.rb:50:in `call'
          # /Users/cdrapier/.gem/ruby/2.3.1/gems/haml-5.0.0/lib/haml/temple_engine.rb:40:in `compile'
          # /Users/cdrapier/.gem/ruby/2.3.1/gems/haml-5.0.0/lib/haml/engine.rb:61:in `initialize'
          # /Users/cdrapier/.gem/ruby/2.3.1/gems/haml-5.0.0/lib/haml/plugin.rb:16:in `new'
          # /Users/cdrapier/.gem/ruby/2.3.1/gems/haml-5.0.0/lib/haml/plugin.rb:16:in `compile'
          # /Users/cdrapier/.gem/ruby/2.3.1/gems/haml-5.0.0/lib/haml/plugin.rb:23:in `call'
          # /Users/cdrapier/.gem/ruby/2.3.1/gems/actionview-4.2.5.1/lib/action_view/template.rb:270:in `compile'

For the little I have looked inside the gem, it seems something strange is going on in attribute_parser.rb, and for some reason a bit unclear to me, the '/abc/' is treated as a key/name of an attribute. But It was a bit difficult to get deeper inside what is happening.
One easy fix on my code part would be to use a variable to contain the result of "#{File.join base_url, '/abc/'}", but I thought this might be a bug that would need to be fix.

Duplicate issue #921: Produces broken syntax for certain calls inside attribute interpolation
Created: 2017-05-03T09:02:20Z
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)

Closing comment (2017-05-03T10:25:20Z): Thank you for reporting. But this is essentially the same as #917 and already fixed on master branch. Please wait for new release.