aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template
diff options
context:
space:
mode:
authorCraig Davey <me@craigdavey.ca>2010-04-09 21:01:32 -0400
committerDavid Heinemeier Hansson <david@loudthinking.com>2010-04-13 17:35:10 -0700
commit5208cc3cf5d54720512ff50c2b97e9f4369aaa27 (patch)
treef10f4ddc330fbc71fc3b3fa7a6201026b4920f59 /actionpack/test/template
parent0ab2ba336f2b094a4235b54a1b17f8bef3fe3b2b (diff)
downloadrails-5208cc3cf5d54720512ff50c2b97e9f4369aaa27.tar.gz
rails-5208cc3cf5d54720512ff50c2b97e9f4369aaa27.tar.bz2
rails-5208cc3cf5d54720512ff50c2b97e9f4369aaa27.zip
Changed translate helper so that it doesn’t mark every translation as safe HTML. Only keys with a "_html" suffix and keys named "html" are considered to be safe HTML. All other translations are left untouched.
Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
Diffstat (limited to 'actionpack/test/template')
-rw-r--r--actionpack/test/template/translation_helper_test.rb17
1 files changed, 16 insertions, 1 deletions
diff --git a/actionpack/test/template/translation_helper_test.rb b/actionpack/test/template/translation_helper_test.rb
index 6782bf06d4..b382b5eb22 100644
--- a/actionpack/test/template/translation_helper_test.rb
+++ b/actionpack/test/template/translation_helper_test.rb
@@ -25,7 +25,7 @@ class TranslationHelperTest < ActiveSupport::TestCase
def test_translation_of_an_array_with_html
expected = '<a href="#">foo</a><a href="#">bar</a>'
- I18n.expects(:translate).with(["foo", "bar"], :raise => true).returns(['<a href="#">foo</a>', '<a href="#">bar</a>'])
+ I18n.expects(:translate).with(["foo", "bar", "html"], :raise => true).returns(['<a href="#">foo</a>', '<a href="#">bar</a>'])
@view = ActionView::Base.new(ActionController::Base.view_paths, {})
assert_equal expected, @view.render(:file => "test/array_translation")
end
@@ -47,4 +47,19 @@ class TranslationHelperTest < ActiveSupport::TestCase
@view = ActionView::Base.new(ActionController::Base.view_paths, {})
assert_equal "foobar", @view.render(:file => "test/scoped_array_translation")
end
+
+ def test_translate_does_not_mark_plain_text_as_safe_html
+ I18n.expects(:translate).with("hello", :raise => true).returns("Hello World")
+ assert_equal false, translate("hello").html_safe?
+ end
+
+ def test_translate_marks_translations_named_html_as_safe_html
+ I18n.expects(:translate).with("html", :raise => true).returns("<a>Hello World</a>")
+ assert translate("html").html_safe?
+ end
+
+ def test_translate_marks_translations_with_a_html_suffix_as_safe_html
+ I18n.expects(:translate).with("hello_html", :raise => true).returns("<a>Hello World</a>")
+ assert translate("hello_html").html_safe?
+ end
end