Skip to content

Commit

Permalink
Merge pull request #903 from k0kubun/dont-preserve-attributes
Browse files Browse the repository at this point in the history
Don't preserve newlines in attributes
  • Loading branch information
k0kubun committed Feb 9, 2017
2 parents cf58469 + e9b8f36 commit c6c085b
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -23,6 +23,7 @@
* Support Rails 5.1 Erubi template handler.
* 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)
* Add temple gem as dependency and create `Haml::TempleEngine` class.
Some methods in `Haml::Compiler` are migrated to `Haml::TempleEngine`. (Takashi Kokubun)
* Drop parser/compiler accessor from `Haml::Engine`. Modify `Haml::Engine#initialize` options
Expand Down
3 changes: 1 addition & 2 deletions lib/haml/attribute_builder.rb
Expand Up @@ -29,15 +29,14 @@ def build_attributes(is_html, attr_wrapper, escape_attrs, hyphenate_data_attrs,
next
end

escaped =
value =
if escape_attrs == :once
Haml::Helpers.escape_once(value)
elsif escape_attrs
Haml::Helpers.html_escape(value)
else
value.to_s
end
value = Haml::Helpers.preserve(escaped)
" #{attr}=#{attr_wrapper}#{value}#{attr_wrapper}"
end
result.compact!
Expand Down
5 changes: 0 additions & 5 deletions test/engine_test.rb
Expand Up @@ -970,8 +970,6 @@ def test_static_attributes_should_be_escaped
render(".atlantis{:style => 'ugly&stupid'} foo"))
assert_equal("<p class='atlantis' style='ugly&amp;stupid'>foo</p>\n",
render("%p.atlantis{:style => 'ugly&stupid'}= 'foo'"))
assert_equal("<p class='atlantis' style='ugly&#x000A;stupid'></p>\n",
render("%p.atlantis{:style => \"ugly\\nstupid\"}"))
end

def test_dynamic_attributes_should_be_escaped
Expand All @@ -981,8 +979,6 @@ def test_dynamic_attributes_should_be_escaped
render("%p{:width => nil, :src => '&foo.png', :alt => String.new} foo"))
assert_equal("<div alt='' src='&amp;foo.png'>foo</div>\n",
render("%div{:width => nil, :src => '&foo.png', :alt => String.new}= 'foo'"))
assert_equal("<img alt='' src='foo&#x000A;.png'>\n",
render("%img{:width => nil, :src => \"foo\\n.png\", :alt => String.new}"))
end

def test_string_double_equals_should_be_esaped
Expand Down Expand Up @@ -1148,7 +1144,6 @@ def test_autoclose_option
def test_attrs_parsed_correctly
assert_equal("<p boom=>biddly='bar =&gt; baz'></p>\n", render("%p{'boom=>biddly' => 'bar => baz'}"))
assert_equal("<p foo,bar='baz, qux'></p>\n", render("%p{'foo,bar' => 'baz, qux'}"))
assert_equal("<p escaped='quo&#x000A;te'></p>\n", render("%p{ :escaped => \"quo\\nte\"}"))
assert_equal("<p escaped='quo4te'></p>\n", render("%p{ :escaped => \"quo\#{2 + 2}te\"}"))
end

Expand Down
5 changes: 0 additions & 5 deletions test/pretty_engine_test.rb
Expand Up @@ -972,8 +972,6 @@ def test_static_attributes_should_be_escaped
render(".atlantis{:style => 'ugly&stupid'} foo"))
assert_equal("<p class='atlantis' style='ugly&amp;stupid'>foo</p>\n",
render("%p.atlantis{:style => 'ugly&stupid'}= 'foo'"))
assert_equal("<p class='atlantis' style='ugly&#x000A;stupid'></p>\n",
render("%p.atlantis{:style => \"ugly\\nstupid\"}"))
end

def test_dynamic_attributes_should_be_escaped
Expand All @@ -983,8 +981,6 @@ def test_dynamic_attributes_should_be_escaped
render("%p{:width => nil, :src => '&foo.png', :alt => String.new} foo"))
assert_equal("<div alt='' src='&amp;foo.png'>foo</div>\n",
render("%div{:width => nil, :src => '&foo.png', :alt => String.new}= 'foo'"))
assert_equal("<img alt='' src='foo&#x000A;.png'>\n",
render("%img{:width => nil, :src => \"foo\\n.png\", :alt => String.new}"))
end

def test_string_double_equals_should_be_esaped
Expand Down Expand Up @@ -1150,7 +1146,6 @@ def test_autoclose_option
def test_attrs_parsed_correctly
assert_equal("<p boom=>biddly='bar =&gt; baz'></p>\n", render("%p{'boom=>biddly' => 'bar => baz'}"))
assert_equal("<p foo,bar='baz, qux'></p>\n", render("%p{'foo,bar' => 'baz, qux'}"))
assert_equal("<p escaped='quo&#x000A;te'></p>\n", render("%p{ :escaped => \"quo\\nte\"}"))
assert_equal("<p escaped='quo4te'></p>\n", render("%p{ :escaped => \"quo\#{2 + 2}te\"}"))
end

Expand Down

0 comments on commit c6c085b

Please sign in to comment.