Permalink
Browse files

Added test and code to throw an error if a translation of an empty st…

…ring is attempted.
  • Loading branch information...
1 parent 16d0c69 commit babe4352435867def35ff8ed2e2360fb27220eb2 @davidw davidw committed with josevalim Sep 21, 2010
Showing with 6 additions and 0 deletions.
  1. +2 −0 lib/i18n.rb
  2. +4 −0 test/i18n_test.rb
View
2 lib/i18n.rb
@@ -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
View
4 test/i18n_test.rb
@@ -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

0 comments on commit babe435

Please sign in to comment.