aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/inflector_test_cases.rb
diff options
context:
space:
mode:
authorBrian McManus <bdmac97@gmail.com>2015-03-20 10:28:25 -0700
committerBrian McManus <bdmac97@gmail.com>2015-03-20 10:28:25 -0700
commit792f625bec5b6c1ab2629e0a6c353df8cc70920e (patch)
tree4e4a8123c160edad126939b061ba51b096e4e295 /activesupport/test/inflector_test_cases.rb
parent5154089c181e9b36753b193bd7ffb141e88232f1 (diff)
downloadrails-792f625bec5b6c1ab2629e0a6c353df8cc70920e.tar.gz
rails-792f625bec5b6c1ab2629e0a6c353df8cc70920e.tar.bz2
rails-792f625bec5b6c1ab2629e0a6c353df8cc70920e.zip
Fixes Inflector#titleize to work with SafeBuffer
The way Inflector#titleize was implemented did not work properly when called on a SafeBuffer object. Using the global `$&` variable in the gsub resulted in calling capitalize on a nil object for reasons I still do not fully understand. Removing the UNSAFE_STRING_METHODS override for the gsub method in SafeBuffer "fixed" the bug but is obviously unacceptable. An example of this is very easy to see in rails console: ActiveSupport::SafeBuffer.new("my test").titleize > NoMethodError: undefined method `capitalize' for nil:NilClass Using the non global version of gsub with a |match| arg passed to the block fixes the problem. Again I do not quite understand why. I noticed that other parts of Inflector were already using the standard block arg version of gsub so I don't think it should be a problem to convert this method to using it as well.
Diffstat (limited to 'activesupport/test/inflector_test_cases.rb')
-rw-r--r--activesupport/test/inflector_test_cases.rb3
1 files changed, 2 insertions, 1 deletions
diff --git a/activesupport/test/inflector_test_cases.rb b/activesupport/test/inflector_test_cases.rb
index 18a8b92eb9..4f7f92ef18 100644
--- a/activesupport/test/inflector_test_cases.rb
+++ b/activesupport/test/inflector_test_cases.rb
@@ -237,7 +237,8 @@ module InflectorTestCases
"maybe you'll be there" => "Maybe You'll Be There",
"¿por qué?" => '¿Por Qué?',
"Fred’s" => "Fred’s",
- "Fred`s" => "Fred`s"
+ "Fred`s" => "Fred`s",
+ ActiveSupport::SafeBuffer.new("confirmation num") => "Confirmation Num"
}
OrdinalNumbers = {