[Haml] [html2haml] Make sure ERB attribute values are unescaped.

This commit is contained in:
Nathan Weizenbaum 2009-10-05 03:39:40 -07:00
parent dc96ffa33e
commit bed9e6f2b7
3 changed files with 11 additions and 1 deletions

View File

@ -3,6 +3,11 @@
* Table of contents
{:toc}
## 2.2.7 (Unreleased)
* Fixed an `html2haml` issue where ERB attribute values
weren't HTML-unescaped before being transformed into Haml.
## [2.2.6](http://github.com/nex3/haml/commit/2.2.6)
* Made the error message when unable to load a dependency for html2haml

View File

@ -202,7 +202,7 @@ module Haml
full_match = nil
ruby_value = value.gsub(%r{<haml:loud>\s*(.+?)\s*</haml:loud>}) do
full_match = $`.empty? && $'.empty?
full_match ? $1: "\#{#{$1}}"
CGI.unescapeHTML(full_match ? $1: "\#{#{$1}}")
end
next if ruby_value == value
[name, full_match ? ruby_value : %("#{ruby_value}")]

View File

@ -64,6 +64,11 @@ class Html2HamlTest < Test::Unit::TestCase
render_rhtml(%Q{<div class="<%= 12 %>!">Bang!</div>})
end
def test_rhtml_in_html_escaped_attribute
assert_equal %(%div{ :class => "foo" }\n Bang!),
render_rhtml(%Q{<div class="<%= "foo" %>">Bang!</div>})
end
def test_rhtml_in_attribute_to_multiple_interpolations
assert_equal %(%div{ :class => "\#{12} + \#{13}" }\n Math is super),
render_rhtml(%Q{<div class="<%= 12 %> + <%= 13 %>">Math is super</div>})