Dup options hash to prevent modifications
`options[:default]` and `options[:raise]` can be mistakenly added to the `options` hash. This can be a problem if you're reusing the same object.
This commit is contained in:
parent
711af75234
commit
6caf3ab51b
@ -34,6 +34,8 @@ module TranslationHelper
|
||||
# naming convention helps to identify translations that include HTML tags so that
|
||||
# you know what kind of output to expect when you call translate in a template.
|
||||
def translate(key, options = {})
|
||||
options = options.dup
|
||||
|
||||
options[:default] = wrap_translate_defaults(options[:default]) if options[:default]
|
||||
|
||||
# If the user has specified rescue_format then pass it all through, otherwise use
|
||||
|
@ -151,4 +151,10 @@ def test_translate_with_array_of_string_defaults
|
||||
translation = translate(:'translations.missing', default: ['A Generic String', 'Second generic string'])
|
||||
assert_equal 'A Generic String', translation
|
||||
end
|
||||
|
||||
def test_translate_doesnt_change_options
|
||||
options = {}
|
||||
translate(:'translations.missing', options)
|
||||
assert_equal options, {}
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user