Skip to content

Commit

Permalink
Merge pull request #10971 from dtaniwaki/escape_link_to_unless
Browse files Browse the repository at this point in the history
Always escape the result of link_to_unless method
  • Loading branch information
rafaelfranca committed Jun 17, 2013
2 parents ce13dc2 + c91e1cc commit 2e3880c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/helpers/url_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def link_to_unless(condition, name, options = {}, html_options = {}, &block)
if block_given?
block.arity <= 1 ? capture(name, &block) : capture(name, options, html_options, &block)
else
name
ERB::Util.html_escape(name)
end
else
link_to(name, options, html_options)
Expand Down
5 changes: 5 additions & 0 deletions actionpack/test/template/url_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,11 @@ def test_link_to_unless
link_to_unless(true, "Showing", url_hash) {
"test"
}

assert_equal %{&lt;b&gt;Showing&lt;/b&gt;}, link_to_unless(true, "<b>Showing</b>", url_hash)
assert_equal %{<a href="/">&lt;b&gt;Showing&lt;/b&gt;</a>}, link_to_unless(false, "<b>Showing</b>", url_hash)
assert_equal %{<b>Showing</b>}, link_to_unless(true, "<b>Showing</b>".html_safe, url_hash)
assert_equal %{<a href="/"><b>Showing</b></a>}, link_to_unless(false, "<b>Showing</b>".html_safe, url_hash)
end

def test_link_to_if
Expand Down

0 comments on commit 2e3880c

Please sign in to comment.