Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Haml::InvalidAttributeNameError with dynamic arguments #917

Closed
cdrapier opened this issue May 1, 2017 · 1 comment
Closed

Haml::InvalidAttributeNameError with dynamic arguments #917

cdrapier opened this issue May 1, 2017 · 1 comment

Comments

@cdrapier
Copy link

cdrapier commented May 1, 2017

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.

@k0kubun k0kubun closed this as completed in c67e672 May 1, 2017
@k0kubun
Copy link
Member

k0kubun commented May 1, 2017

Oh, sorry... that's definitely a bug. Fixed in c67e672. Thank you for reporting.

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Jun 21, 2017
## 5.0.1

Released on May 3, 2017
([diff](haml/haml@v5.0.0...v5.0.1)).

* Fix parsing attributes including string interpolation. [#917](haml/haml#917) [#921](haml/haml#921)
* Stop distributing test files in gem package and allow installing on Windows.
* Use ActionView's Erubi/Erubis handler for erb filter only on ActionView. [#914](haml/haml#914)

## 5.0.0

Released on April 26, 2017
([diff](haml/haml@4.0.7...v5.0.0)).

Breaking Changes

* Haml now requires Ruby 2.0.0 or above.
* Rails 3 is no longer supported, matching the official
  [Maintenance Policy for Ruby on Rails](http://weblog.rubyonrails.org/2013/2/24/maintenance-policy-for-ruby-on-rails/).
  (Tee Parham)
* The `haml` command's debug option (`-d`) no longer executes the Haml code, but
  rather checks the generated Ruby syntax for errors.
* Drop parser/compiler accessor from `Haml::Engine`. Modify `Haml::Engine#initialize` options
  or `Haml::Template.options` instead. (Takashi Kokubun)
* Drop dynamic quotes support and always escape `'` for `escape_html`/`escape_attrs` instead.
  Also, escaped results are slightly changed and always unified to the same characters. (Takashi Kokubun)
* Don't preserve newlines in attributes. (Takashi Kokubun)
* HTML escape interpolated code in filters.
  [#770](haml/haml#770)
  (Matt Wildig)

        :javascript
          #{JSON.generate(foo: "bar")}
        Haml 4 output: {"foo":"bar"}
        Haml 5 output: {"foo":"bar"}

Added

* Add a tracing option. When enabled, Haml will output a data-trace attribute on each tag showing the path
  to the source Haml file from which it was generated. Thanks [Alex Babkin](https://github.com/ababkin).
* Add `haml_tag_if` to render a block, conditionally wrapped in another element (Matt Wildig)
* Support Rails 5.1 Erubi template handler.
* Support Sprockets 3. Thanks [Sam Davies](https://github.com/samphilipd) and [Jeremy Venezia](https://github.com/jvenezia).
* General performance and memory usage improvements. (Akira Matsuda)
* Analyze attribute values by Ripper and render static attributes beforehand. (Takashi Kokubun)
* Optimize attribute rendering about 3x faster. (Takashi Kokubun)
* Add temple gem as dependency and create `Haml::TempleEngine` class.
  Some methods in `Haml::Compiler` are migrated to `Haml::TempleEngine`. (Takashi Kokubun)

Fixed

* Fix for attribute merging. When an attribute method (or literal nested hash)
  was used in an old style attribute hash and there is also a (non-static) new
  style hash there is an error. The fix can result in different behavior in
  some circumstances. See the [commit message](https://github.com/haml/haml/tree/e475b015d3171fb4c4f140db304f7970c787d6e3)
  for detailed info. (Matt Wildig)
* Make escape_once respect hexadecimal references. (Matt Wildig)
* Don't treat the 'data' attribute specially when merging attribute hashes. (Matt Wildig and Norman Clarke)
* Fix #@foo and #$foo style interpolation that was not working in html_safe mode. (Akira Matsuda)
* Allow `@` as tag's class name. Thanks [Joe Bartlett](https://github.com/redoPop).
* Raise `Haml::InvalidAttributeNameError` when attribute name includes invalid characters. (Takashi Kokubun)
* Don't ignore unexpected exceptions on initializing `ActionView::OutputBuffer`. (Takashi Kokubun)
jsonn pushed a commit to jsonn/pkgsrc that referenced this issue Jun 21, 2017
## 5.0.1

Released on May 3, 2017
([diff](haml/haml@v5.0.0...v5.0.1)).

* Fix parsing attributes including string interpolation. [#917](haml/haml#917) [#921](haml/haml#921)
* Stop distributing test files in gem package and allow installing on Windows.
* Use ActionView's Erubi/Erubis handler for erb filter only on ActionView. [#914](haml/haml#914)

## 5.0.0

Released on April 26, 2017
([diff](haml/haml@4.0.7...v5.0.0)).

Breaking Changes

* Haml now requires Ruby 2.0.0 or above.
* Rails 3 is no longer supported, matching the official
  [Maintenance Policy for Ruby on Rails](http://weblog.rubyonrails.org/2013/2/24/maintenance-policy-for-ruby-on-rails/).
  (Tee Parham)
* The `haml` command's debug option (`-d`) no longer executes the Haml code, but
  rather checks the generated Ruby syntax for errors.
* Drop parser/compiler accessor from `Haml::Engine`. Modify `Haml::Engine#initialize` options
  or `Haml::Template.options` instead. (Takashi Kokubun)
* Drop dynamic quotes support and always escape `'` for `escape_html`/`escape_attrs` instead.
  Also, escaped results are slightly changed and always unified to the same characters. (Takashi Kokubun)
* Don't preserve newlines in attributes. (Takashi Kokubun)
* HTML escape interpolated code in filters.
  [#770](haml/haml#770)
  (Matt Wildig)

        :javascript
          #{JSON.generate(foo: "bar")}
        Haml 4 output: {"foo":"bar"}
        Haml 5 output: {"foo":"bar"}

Added

* Add a tracing option. When enabled, Haml will output a data-trace attribute on each tag showing the path
  to the source Haml file from which it was generated. Thanks [Alex Babkin](https://github.com/ababkin).
* Add `haml_tag_if` to render a block, conditionally wrapped in another element (Matt Wildig)
* Support Rails 5.1 Erubi template handler.
* Support Sprockets 3. Thanks [Sam Davies](https://github.com/samphilipd) and [Jeremy Venezia](https://github.com/jvenezia).
* General performance and memory usage improvements. (Akira Matsuda)
* Analyze attribute values by Ripper and render static attributes beforehand. (Takashi Kokubun)
* Optimize attribute rendering about 3x faster. (Takashi Kokubun)
* Add temple gem as dependency and create `Haml::TempleEngine` class.
  Some methods in `Haml::Compiler` are migrated to `Haml::TempleEngine`. (Takashi Kokubun)

Fixed

* Fix for attribute merging. When an attribute method (or literal nested hash)
  was used in an old style attribute hash and there is also a (non-static) new
  style hash there is an error. The fix can result in different behavior in
  some circumstances. See the [commit message](https://github.com/haml/haml/tree/e475b015d3171fb4c4f140db304f7970c787d6e3)
  for detailed info. (Matt Wildig)
* Make escape_once respect hexadecimal references. (Matt Wildig)
* Don't treat the 'data' attribute specially when merging attribute hashes. (Matt Wildig and Norman Clarke)
* Fix #@foo and #$foo style interpolation that was not working in html_safe mode. (Akira Matsuda)
* Allow `@` as tag's class name. Thanks [Joe Bartlett](https://github.com/redoPop).
* Raise `Haml::InvalidAttributeNameError` when attribute name includes invalid characters. (Takashi Kokubun)
* Don't ignore unexpected exceptions on initializing `ActionView::OutputBuffer`. (Takashi Kokubun)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants