aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Sarnacki <drogus@gmail.com>2012-03-26 15:58:01 -0700
committerPiotr Sarnacki <drogus@gmail.com>2012-03-26 15:58:01 -0700
commita2126abc112187baa34c52dba8cbcdf47a9fc9aa (patch)
treebaad9bd98d8fcf9125c4036f0ee796b34da7af7c
parentde9c0ef8eff8bd9c92332b4b854772519b4ef7b9 (diff)
parent633ee64e20da05ddbcab67558351733ba511a444 (diff)
downloadrails-a2126abc112187baa34c52dba8cbcdf47a9fc9aa.tar.gz
rails-a2126abc112187baa34c52dba8cbcdf47a9fc9aa.tar.bz2
rails-a2126abc112187baa34c52dba8cbcdf47a9fc9aa.zip
Merge pull request #5592 from nashby/fix-issue-5584
String#titleize works properly with smart quotes
-rw-r--r--activesupport/lib/active_support/inflector/methods.rb6
-rw-r--r--activesupport/test/inflector_test_cases.rb4
2 files changed, 7 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb
index 48ea5653c7..4cebad742f 100644
--- a/activesupport/lib/active_support/inflector/methods.rb
+++ b/activesupport/lib/active_support/inflector/methods.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
require 'active_support/inflector/inflections'
module ActiveSupport
@@ -112,7 +114,7 @@ module ActiveSupport
# "TheManWithoutAPast".titleize # => "The Man Without A Past"
# "raiders_of_the_lost_ark".titleize # => "Raiders Of The Lost Ark"
def titleize(word)
- humanize(underscore(word)).gsub(/\b('?[a-z])/) { $1.capitalize }
+ humanize(underscore(word)).gsub(/\b(['’`]?[a-z])/) { $1.capitalize }
end
# Create the name of a table like Rails does for models to table names. This method
@@ -209,7 +211,7 @@ module ActiveSupport
def constantize(camel_cased_word) #:nodoc:
names = camel_cased_word.split('::')
names.shift if names.empty? || names.first.empty?
-
+
names.inject(Object) do |constant, name|
constant.const_get(name, false)
end
diff --git a/activesupport/test/inflector_test_cases.rb b/activesupport/test/inflector_test_cases.rb
index 809b8b46c9..879c3c1125 100644
--- a/activesupport/test/inflector_test_cases.rb
+++ b/activesupport/test/inflector_test_cases.rb
@@ -220,7 +220,9 @@ module InflectorTestCases
'Actionwebservice' => 'Actionwebservice',
"david's code" => "David's Code",
"David's code" => "David's Code",
- "david's Code" => "David's Code"
+ "david's Code" => "David's Code",
+ "Fred’s" => "Fred’s",
+ "Fred`s" => "Fred`s"
}
OrdinalNumbers = {