Permalink
Browse files

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.
  • Loading branch information...
josepjaume committed May 12, 2014
1 parent 711af75 commit 6caf3ab51b422e08135cbfbdaeedb94b1f6c312c
@@ -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

0 comments on commit 6caf3ab

Please sign in to comment.