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

[FIX] Raise ArgumentError on nil key in exists? #696

Merged
merged 1 commit into from
Sep 15, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/i18n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ def interpolation_keys(key, **options)
def exists?(key, _locale = nil, locale: _locale, **options)
locale ||= config.locale
raise Disabled.new('exists?') if locale == false
raise I18n::ArgumentError if key.is_a?(String) && key.empty?
raise I18n::ArgumentError if (key.is_a?(String) && key.empty?) || key.nil?

config.backend.exists?(locale, key, options)
end

Expand Down
4 changes: 4 additions & 0 deletions test/i18n_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ def setup
assert_raises(I18n::ArgumentError) { I18n.interpolation_keys(["bad-argument"]) }
end

test "exists? given nil raises I18n::ArgumentError" do
assert_raises(I18n::ArgumentError) { I18n.exists?(nil) }
end

test "exists? given an existing key will return true" do
assert_equal true, I18n.exists?(:currency)
end
Expand Down
Loading