Permalink
Browse files

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.
  • Loading branch information...
pixeltrix committed Mar 6, 2017
1 parent 5369253 commit 48b37f127fb44b787ae6c0710982d7949b14454f
@@ -1,3 +1,19 @@
* 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.
*Andrew White*
* Add `rfc3339` aliases to `xmlschema` for `Time` and `ActiveSupport::TimeWithZone`
For naming consistency when using the RFC 3339 profile of ISO 8601 in applications.
@@ -161,7 +161,7 @@ def upcase_first(string)
# 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

This comment has been minimized.

@Gaurav2728

Gaurav2728 Mar 6, 2017

Contributor

👍

# Creates the name of a table like Rails does for models to table names.
@@ -271,6 +271,7 @@ module InflectorTestCases
"¿por qué?" => "¿Por Qué?",
"Fred’s" => "Fred’s",
"Fred`s" => "Fred`s",
"this was 'fake news'" => "This Was 'Fake News'",
ActiveSupport::SafeBuffer.new("confirmation num") => "Confirmation Num"
}

0 comments on commit 48b37f1

Please sign in to comment.