Skip to content

Commit

Permalink
Merge pull request #48800 from robinjam/fix-humanize-nil
Browse files Browse the repository at this point in the history
Fix `ActiveSupport::Inflector.humanize(nil)`
  • Loading branch information
byroot committed Jul 25, 2023
1 parent 2fde2bd commit b18b9df
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions activesupport/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* Fix `ActiveSupport::Inflector.humanize(nil)` raising ``NoMethodError: undefined method `end_with?' for nil:NilClass``.

*James Robinson*

* Fix `Enumerable#sum` for `Enumerator#lazy`.

*fatkodima*, *Matthew Draper*, *Jonathan Hefner*
Expand Down
2 changes: 1 addition & 1 deletion activesupport/lib/active_support/inflector/methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,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

Expand Down
4 changes: 4 additions & 0 deletions activesupport/test/inflector_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,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))
Expand Down

0 comments on commit b18b9df

Please sign in to comment.