diff options
author | Andrew White <andrew.white@unboxed.co> | 2017-03-06 17:40:15 +0000 |
---|---|---|
committer | Andrew White <andrew.white@unboxed.co> | 2017-03-06 17:51:03 +0000 |
commit | 48b37f127fb44b787ae6c0710982d7949b14454f (patch) | |
tree | d3def9f511624a1c9c376590f4a1c7837ef370f2 /activesupport/lib/active_support | |
parent | 53692535896437f7c67093820f09440c672fa215 (diff) | |
download | rails-48b37f127fb44b787ae6c0710982d7949b14454f.tar.gz rails-48b37f127fb44b787ae6c0710982d7949b14454f.tar.bz2 rails-48b37f127fb44b787ae6c0710982d7949b14454f.zip |
Update `titlelize` regex to allow apostrophes
In 4b685aa the regex in `titlelize` was updated to not match
apostrophes to better reflect the nature of the transformation.
Unfortunately this had the side effect of breaking capitalization
on the first word of a sub-string, e.g:
>> "This was 'fake news'".titleize
=> "This Was 'fake News'"
This is fixed by extending the look-behind to also check for a
word character on the other side of the apostrophe.
Fixes #28312.
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/inflector/methods.rb | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb index 8ccb735c6d..51c221ac0e 100644 --- a/activesupport/lib/active_support/inflector/methods.rb +++ b/activesupport/lib/active_support/inflector/methods.rb @@ -161,7 +161,7 @@ module ActiveSupport # titleize('TheManWithoutAPast') # => "The Man Without A Past" # titleize('raiders_of_the_lost_ark') # => "Raiders Of The Lost Ark" def titleize(word) - humanize(underscore(word)).gsub(/\b(?<!['’`])[a-z]/) { |match| match.capitalize } + humanize(underscore(word)).gsub(/\b(?<!\w['’`])[a-z]/) { |match| match.capitalize } end # Creates the name of a table like Rails does for models to table names. |