diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-12-04 16:25:50 -0800 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-12-04 16:25:50 -0800 |
commit | d1cec0841db059e2daece4486fc30c8a14d23993 (patch) | |
tree | 05f338e912a29ec109e7f2d94af85ac6451e8fdf | |
parent | 49ed8a1a628ff8b7aa089df241cd3f487cfbd06f (diff) | |
parent | c1d5477b63e73dadec9f284fa55ec22d81f3bf36 (diff) | |
download | rails-d1cec0841db059e2daece4486fc30c8a14d23993.tar.gz rails-d1cec0841db059e2daece4486fc30c8a14d23993.tar.bz2 rails-d1cec0841db059e2daece4486fc30c8a14d23993.zip |
Merge pull request #13183 from sorah/never_ignore_i18n_translate_raise_option
Escalate missing error when :raise is true in translate helper, fix regression introduced by security fix.
-rw-r--r-- | actionpack/CHANGELOG.md | 7 | ||||
-rw-r--r-- | actionview/lib/action_view/helpers/translation_helper.rb | 10 | ||||
-rw-r--r-- | actionview/test/template/translation_helper_test.rb | 6 |
3 files changed, 22 insertions, 1 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 83e188a41b..26ba89eb33 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,3 +1,10 @@ +* Fix regression when using `ActionView::Helpers::TranslationHelper#translate` with + `options[:raise]`. + + This regression was introduced at ec16ba75a5493b9da972eea08bae630eba35b62f. + + *Shota Fukumori (sora_h)* + * Introducing Variants We often want to render different html/json/xml templates for phones, diff --git a/actionview/lib/action_view/helpers/translation_helper.rb b/actionview/lib/action_view/helpers/translation_helper.rb index a1a2bebb6e..3ae1df04fe 100644 --- a/actionview/lib/action_view/helpers/translation_helper.rb +++ b/actionview/lib/action_view/helpers/translation_helper.rb @@ -38,7 +38,13 @@ module ActionView # If the user has specified rescue_format then pass it all through, otherwise use # raise and do the work ourselves - options[:raise] = true unless options.key?(:raise) || options.key?(:rescue_format) + if options.key?(:raise) || options.key?(:rescue_format) + raise_error = options[:raise] || options[:rescue_format] + else + raise_error = false + options[:raise] = true + end + if html_safe_translation_key?(key) html_safe_options = options.dup options.except(*I18n::RESERVED_KEYS).each do |name, value| @@ -53,6 +59,8 @@ module ActionView I18n.translate(scope_key_by_partial(key), options) end rescue I18n::MissingTranslationData => e + raise e if raise_error + keys = I18n.normalize_keys(e.locale, e.key, e.options[:scope]) content_tag('span', keys.last.to_s.titleize, :class => 'translation_missing', :title => "translation missing: #{keys.join('.')}") end diff --git a/actionview/test/template/translation_helper_test.rb b/actionview/test/template/translation_helper_test.rb index 0dfe47f5f4..269714fad0 100644 --- a/actionview/test/template/translation_helper_test.rb +++ b/actionview/test/template/translation_helper_test.rb @@ -53,6 +53,12 @@ class TranslationHelperTest < ActiveSupport::TestCase assert_equal false, translate(:"translations.missing", :rescue_format => nil).html_safe? end + def test_raises_missing_translation_message_with_raise_option + assert_raise(I18n::MissingTranslationData) do + translate(:"translations.missing", :raise => true) + end + end + def test_i18n_translate_defaults_to_nil_rescue_format expected = 'translation missing: en.translations.missing' assert_equal expected, I18n.translate(:"translations.missing") |