Skip to content

Commit 0c1028f

Browse files
committed
Fix nil translation key lookup in controllers
1 parent 903656f commit 0c1028f

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

actionpack/lib/abstract_controller/translation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module Translation
1515
# to translate many keys within the same controller / action and gives you a
1616
# simple framework for scoping them consistently.
1717
def translate(key, **options)
18-
if key.start_with?(".")
18+
if key&.start_with?(".")
1919
path = controller_path.tr("/", ".")
2020
defaults = [:"#{path}#{key}"]
2121
defaults << options[:default] if options[:default]

actionpack/test/abstract/translation_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ def test_lazy_lookup
6565
end
6666
end
6767

68+
def test_nil_key_lookup
69+
default = "foo"
70+
assert_equal default, @controller.t(nil, default: default)
71+
end
72+
6873
def test_lazy_lookup_with_symbol
6974
@controller.stub :action_name, :index do
7075
assert_equal "bar", @controller.t(:'.foo')

0 commit comments

Comments
 (0)