Skip to content

Commit

Permalink
Added test and code to throw an error if a translation of an empty st…
Browse files Browse the repository at this point in the history
…ring is attempted.
  • Loading branch information
davidw authored and josevalim committed Sep 21, 2010
1 parent 16d0c69 commit babe435
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/i18n.rb
Expand Up @@ -151,6 +151,8 @@ def translate(*args)
locale = options.delete(:locale) || config.locale
raises = options.delete(:raise)

raise I18n::ArgumentError if key.is_a?(String) && key.empty?

if key.is_a?(Array)
key.map { |k| backend.translate(locale, k, options) }
else
Expand Down
4 changes: 4 additions & 0 deletions test/i18n_test.rb
Expand Up @@ -176,6 +176,10 @@ def test_translate_given_a_bogus_key_raises_missing_translation_data
assert_equal "translation missing: en, bogus", I18n.t(:bogus)
end

def test_translate_empty_string_raises_argument_error
assert_raise(I18n::ArgumentError) { I18n.t("") }
end

def test_localize_nil_raises_argument_error
assert_raise(I18n::ArgumentError) { I18n.l nil }
end
Expand Down

0 comments on commit babe435

Please sign in to comment.