aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2013-06-17 10:01:03 -0700
committerRafael Mendonça França <rafaelmfranca@gmail.com>2013-06-17 10:01:03 -0700
commit2e3880ca6278ea6a9e938393b1288ded07868654 (patch)
tree6ed9ac5faf10b6dfb1903b1fa867844be9d9f373
parentce13dc28e47d739545da5732a2b23903c9b7ed84 (diff)
parentc91e1cca4398aeb1e2d86b96f72b60e2b1b400ad (diff)
downloadrails-2e3880ca6278ea6a9e938393b1288ded07868654.tar.gz
rails-2e3880ca6278ea6a9e938393b1288ded07868654.tar.bz2
rails-2e3880ca6278ea6a9e938393b1288ded07868654.zip
Merge pull request #10971 from dtaniwaki/escape_link_to_unless
Always escape the result of link_to_unless method
-rw-r--r--actionpack/lib/action_view/helpers/url_helper.rb2
-rw-r--r--actionpack/test/template/url_helper_test.rb5
2 files changed, 6 insertions, 1 deletions
diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb
index 8a83f6f356..19e5941971 100644
--- a/actionpack/lib/action_view/helpers/url_helper.rb
+++ b/actionpack/lib/action_view/helpers/url_helper.rb
@@ -380,7 +380,7 @@ module ActionView
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)
diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb
index f63f235a5c..eb4349015a 100644
--- a/actionpack/test/template/url_helper_test.rb
+++ b/actionpack/test/template/url_helper_test.rb
@@ -348,6 +348,11 @@ class UrlHelperTest < ActiveSupport::TestCase
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