mirror of
https://github.com/github/rails.git
synced 2026-01-09 14:48:08 -05:00
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. Conflicts: actionpack/CHANGELOG.md
This commit is contained in:
@@ -1,3 +1,12 @@
|
||||
* Fix regression when using `ActionView::Helpers::TranslationHelper#translate` with
|
||||
`options[:raise]`.
|
||||
|
||||
This regression was introduced at ec16ba75a5493b9da972eea08bae630eba35b62f.
|
||||
|
||||
*Shota Fukumori (sora_h)*
|
||||
|
||||
## Rails 3.2.16 ##
|
||||
|
||||
* Deep Munge the parameters for GET and POST Fixes CVE-2013-6417
|
||||
|
||||
* Stop using i18n's built in HTML error handling. Fixes: CVE-2013-4491
|
||||
|
||||
@@ -36,7 +36,13 @@ module ActionView
|
||||
def translate(key, options = {})
|
||||
# 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|
|
||||
@@ -51,6 +57,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
|
||||
|
||||
@@ -52,6 +52,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")
|
||||
|
||||
Reference in New Issue
Block a user