Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip nils out of default translations. Fixes #19419 #19421

Merged
merged 1 commit into from
Mar 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions actionview/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
* `translate` should accept nils as members of the `:default`
parameter without raising a translation missing error. Fixes a
regression introduced 362557e.

Fixes #19419

*Justin Coyne*


* `number_to_percentage` does not crash with `Float::NAN` or `Float::INFINITY`
as input when `precision: 0` is used.

Expand Down
2 changes: 1 addition & 1 deletion actionview/lib/action_view/helpers/translation_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module TranslationHelper
def translate(key, options = {})
options = options.dup
has_default = options.has_key?(:default)
remaining_defaults = Array(options.delete(:default))
remaining_defaults = Array(options.delete(:default)).compact

if has_default && !remaining_defaults.first.kind_of?(Symbol)
options[:default] = remaining_defaults.shift
Expand Down
5 changes: 5 additions & 0 deletions actionview/test/template/translation_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ def test_translate_with_array_of_string_defaults
assert_equal 'A Generic String', translation
end

def test_translate_with_array_of_defaults_with_nil
translation = translate(:'translations.missing', default: [:'also_missing', nil, 'A Generic String'])
assert_equal 'A Generic String', translation
end

def test_translate_does_not_change_options
options = {}
translate(:'translations.missing', options)
Expand Down