aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorAndrew White <andrew.white@unboxed.co>2017-03-06 17:40:15 +0000
committerAndrew White <andrew.white@unboxed.co>2017-03-06 17:51:03 +0000
commit48b37f127fb44b787ae6c0710982d7949b14454f (patch)
treed3def9f511624a1c9c376590f4a1c7837ef370f2 /activesupport
parent53692535896437f7c67093820f09440c672fa215 (diff)
downloadrails-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')
-rw-r--r--activesupport/CHANGELOG.md16
-rw-r--r--activesupport/lib/active_support/inflector/methods.rb2
-rw-r--r--activesupport/test/inflector_test_cases.rb1
3 files changed, 18 insertions, 1 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index 58956ad0e8..fb7379d153 100644
--- a/activesupport/CHANGELOG.md
+++ b/activesupport/CHANGELOG.md
@@ -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.
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.
diff --git a/activesupport/test/inflector_test_cases.rb b/activesupport/test/inflector_test_cases.rb
index b660987d92..f3352e3301 100644
--- a/activesupport/test/inflector_test_cases.rb
+++ b/activesupport/test/inflector_test_cases.rb
@@ -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"
}