From 5208cc3cf5d54720512ff50c2b97e9f4369aaa27 Mon Sep 17 00:00:00 2001 From: Craig Davey Date: Fri, 9 Apr 2010 21:01:32 -0400 Subject: =?UTF-8?q?Changed=20translate=20helper=20so=20that=20it=20doesn?= =?UTF-8?q?=E2=80=99t=20mark=20every=20translation=20as=20safe=20HTML.=20O?= =?UTF-8?q?nly=20keys=20with=20a=20"=5Fhtml"=20suffix=20and=20keys=20named?= =?UTF-8?q?=20"html"=20are=20considered=20to=20be=20safe=20HTML.=20All=20o?= =?UTF-8?q?ther=20translations=20are=20left=20untouched.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: David Heinemeier Hansson --- actionpack/test/fixtures/test/array_translation.erb | 2 +- actionpack/test/template/translation_helper_test.rb | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/fixtures/test/array_translation.erb b/actionpack/test/fixtures/test/array_translation.erb index 12c0763313..def3a1a0c1 100644 --- a/actionpack/test/fixtures/test/array_translation.erb +++ b/actionpack/test/fixtures/test/array_translation.erb @@ -1 +1 @@ -<%= t(['foo', 'bar']) %> \ No newline at end of file +<%= t(['foo', 'bar', 'html']) %> \ No newline at end of file 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 = 'foobar' - I18n.expects(:translate).with(["foo", "bar"], :raise => true).returns(['foo', 'bar']) + I18n.expects(:translate).with(["foo", "bar", "html"], :raise => true).returns(['foo', 'bar']) @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("Hello World") + 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("Hello World") + assert translate("hello_html").html_safe? + end end -- cgit v1.2.3