aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2013-06-14 02:19:25 -0700
committerXavier Noria <fxn@hashref.com>2013-06-14 02:19:25 -0700
commit85bb7d9af16dafccd3c3d2394a75050951f8804c (patch)
treebad591f0a7c1b59ee39cb51f7d25972ab768ee8d /activesupport/lib/active_support
parent90a6059dd2df748e002618eaacab6b46f50d4bfc (diff)
parent7fd36f307a86b64d05f9171ff050c4af3b45725c (diff)
downloadrails-85bb7d9af16dafccd3c3d2394a75050951f8804c.tar.gz
rails-85bb7d9af16dafccd3c3d2394a75050951f8804c.tar.bz2
rails-85bb7d9af16dafccd3c3d2394a75050951f8804c.zip
Merge pull request #10943 from killthekitten/10932_constantize_empty
Fix #10932. Treat "" and "::" as invalid on constantize
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/inflector/methods.rb7
1 files changed, 6 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb
index 39648727fd..665545db3b 100644
--- a/activesupport/lib/active_support/inflector/methods.rb
+++ b/activesupport/lib/active_support/inflector/methods.rb
@@ -219,7 +219,12 @@ module ActiveSupport
# unknown.
def constantize(camel_cased_word)
names = camel_cased_word.split('::')
- names.shift if names.empty? || names.first.empty?
+
+ # Trigger a builtin NameError exception including the ill-formed constant in the message.
+ Object.const_get(camel_cased_word) if names.empty?
+
+ # Remove the first blank element in case of '::ClassName' notation.
+ names.shift if names.size > 1 && names.first.empty?
names.inject(Object) do |constant, name|
if constant == Object