1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix titleize to work with parentheses (#37029)

* Fix titleize to work with parentheses

* Add extra test case

* Update code to also ignore the ')' character and add a test case
This commit is contained in:
Alberto Rocha 2019-08-23 22:10:47 -03:00 committed by Kasper Timm Hansen
parent 28775ff3a2
commit 892c30d025
2 changed files with 4 additions and 1 deletions

View file

@ -173,7 +173,7 @@ module ActiveSupport
# titleize('raiders_of_the_lost_ark') # => "Raiders Of The Lost Ark"
# titleize('string_ending_with_id', keep_id_suffix: true) # => "String Ending With Id"
def titleize(word, keep_id_suffix: false)
humanize(underscore(word), keep_id_suffix: keep_id_suffix).gsub(/\b(?<!\w['`])[a-z]/) do |match|
humanize(underscore(word), keep_id_suffix: keep_id_suffix).gsub(/\b(?<!\w['`()])[a-z]/) do |match|
match.capitalize
end
end

View file

@ -289,6 +289,9 @@ module InflectorTestCases
"Freds" => "Freds",
"Fred`s" => "Fred`s",
"this was 'fake news'" => "This Was 'Fake News'",
"new name(s)" => "New Name(s)",
"new (names)" => "New (Names)",
"their (mis)deeds" => "Their (Mis)deeds",
ActiveSupport::SafeBuffer.new("confirmation num") => "Confirmation Num"
}