Skip to content
This repository was archived by the owner on Dec 28, 2023. It is now read-only.

Commit a6ea927

Browse files
I18n.locale= and default_locale= now fail given junk values.
Only strings and nil allowed.
1 parent 8fc94e7 commit a6ea927

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/i18n/config.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def locale
99
# Sets the current locale pseudo-globally, i.e. in the Thread.current hash.
1010
def locale=(locale)
1111
I18n.enforce_available_locales!(locale)
12-
@locale = locale.to_sym rescue nil
12+
@locale = locale && locale.to_sym
1313
end
1414

1515
# Returns the current backend. Defaults to +Backend::Simple+.
@@ -30,7 +30,7 @@ def default_locale
3030
# Sets the current default locale. Used to set a custom default locale.
3131
def default_locale=(locale)
3232
I18n.enforce_available_locales!(locale)
33-
@@default_locale = locale.to_sym rescue nil
33+
@@default_locale = locale && locale.to_sym
3434
end
3535

3636
# Returns an array of locales for which translations are available.

test/i18n_test.rb

+8
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ def setup
3737
end
3838
end
3939

40+
test "default_locale= doesn't ignore junk" do
41+
assert_raise(NoMethodError) { I18n.default_locale = Class }
42+
end
43+
4044
test "raises an I18n::InvalidLocale exception when setting an unavailable default locale" do
4145
begin
4246
I18n.config.enforce_available_locales = true
@@ -57,6 +61,10 @@ def setup
5761
I18n.locale = :en
5862
end
5963

64+
test "locale= doesn't ignore junk" do
65+
assert_raise(NoMethodError) { I18n.locale = Class }
66+
end
67+
6068
test "raises an I18n::InvalidLocale exception when setting an unavailable locale" do
6169
begin
6270
I18n.config.enforce_available_locales = true

0 commit comments

Comments
 (0)