Skip to content

Commit

Permalink
Fixed HTML escaping after call to html_tag
Browse files Browse the repository at this point in the history
The old value of _haml_concat_raw was not being set correctly, hence
calls to haml_concat after a call to haml_tag would result in the output
of haml_concat being appeneded unescaped.

Resolves #718
  • Loading branch information
norman committed Jan 7, 2014
1 parent c12ea70 commit 4d575c1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/haml/helpers/action_view_extensions.rb
Expand Up @@ -45,8 +45,8 @@ def page_class
# @yield A block in which all input to `#haml_concat` is treated as raw.
# @see Haml::Util#rails_xss_safe?
def with_raw_haml_concat
old = instance_variable_defined?('@_haml_concat_raw') ? @_haml_concat_raw : false
@_haml_concat_raw = true
old = @_haml_concat_raw
yield
ensure
@_haml_concat_raw = old
Expand Down
19 changes: 19 additions & 0 deletions test/helper_test.rb
Expand Up @@ -14,6 +14,16 @@ module Haml::Helpers
def something_that_uses_haml_concat
haml_concat('foo').to_s
end

def render_something_with_haml_concat
haml_concat "<p>"
end

def render_something_with_haml_tag_and_concat
haml_tag 'p' do
haml_concat '<foo>'
end
end
end

class HelperTest < MiniTest::Unit::TestCase
Expand Down Expand Up @@ -42,6 +52,15 @@ def render(text, options = {})
super
end

def test_rendering_with_escapes
output = render(<<-HAML, :action_view)
- render_something_with_haml_concat
- render_something_with_haml_tag_and_concat
- render_something_with_haml_concat
HAML
assert_equal("&lt;p&gt;\n<p>\n <foo>\n</p>\n&lt;p&gt;\n", output)
end

def test_flatten
assert_equal("FooBar", Haml::Helpers.flatten("FooBar"))

Expand Down

0 comments on commit 4d575c1

Please sign in to comment.