From 016b81f0b205b0d59aa59a22bdaa9fd503a22a6b Mon Sep 17 00:00:00 2001 From: James Robinson Date: Tue, 25 Jul 2023 16:47:47 +0100 Subject: [PATCH] Fix `ActiveSupport::Inflector.humanize(nil)` --- activesupport/CHANGELOG.md | 4 ++++ activesupport/lib/active_support/inflector/methods.rb | 2 +- activesupport/test/inflector_test.rb | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 37d23f12ab1..b2206764b1e 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,7 @@ +* Fix `ActiveSupport::Inflector.humanize(nil)` raising ``NoMethodError: undefined method `end_with?' for nil:NilClass``. + + *James Robinson* + * Don't show secrets for `ActiveSupport::KeyGenerator#inspect`. Before: diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb index 2247e02db1b..9a8d77ff7f4 100644 --- a/activesupport/lib/active_support/inflector/methods.rb +++ b/activesupport/lib/active_support/inflector/methods.rb @@ -139,7 +139,7 @@ module ActiveSupport result.tr!("_", " ") result.lstrip! - if !keep_id_suffix && lower_case_and_underscored_word.end_with?("_id") + if !keep_id_suffix && lower_case_and_underscored_word&.end_with?("_id") result.delete_suffix!(" id") end diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index ec60a0a2076..b4b20eb630b 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -380,6 +380,10 @@ class InflectorTest < ActiveSupport::TestCase end end + def test_humanize_nil + assert_equal("", ActiveSupport::Inflector.humanize(nil)) + end + def test_humanize_without_capitalize UnderscoreToHumanWithoutCapitalize.each do |underscore, human| assert_equal(human, ActiveSupport::Inflector.humanize(underscore, capitalize: false))