diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 37d23f12ab..b2206764b1 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 2247e02db1..9a8d77ff7f 100644 --- a/activesupport/lib/active_support/inflector/methods.rb +++ b/activesupport/lib/active_support/inflector/methods.rb @@ -139,7 +139,7 @@ def humanize(lower_case_and_underscored_word, capitalize: true, keep_id_suffix: 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 ec60a0a207..b4b20eb630 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -380,6 +380,10 @@ def test_humanize 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))