aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2012-03-30 06:04:01 -0700
committerJosé Valim <jose.valim@gmail.com>2012-03-30 06:04:01 -0700
commit34320cd6ba3423be7e0828c1486601aca53abc82 (patch)
treebd9d5a29cc030ee3e7aaad0dbdea8972da37f806 /activesupport/lib/active_support/core_ext/module/attribute_accessors.rb
parentb69298e01d5879fd9381fe27dffdbb50f14721f0 (diff)
parent96b951ce24651aa1527b16f4ec293c716757e8b0 (diff)
downloadrails-34320cd6ba3423be7e0828c1486601aca53abc82.tar.gz
rails-34320cd6ba3423be7e0828c1486601aca53abc82.tar.bz2
rails-34320cd6ba3423be7e0828c1486601aca53abc82.zip
Merge pull request #5668 from plashchynski/validate_attribute_name_in_class_and_module_attribute_accessors
validate attribute names in class and module attribute accessors
Diffstat (limited to 'activesupport/lib/active_support/core_ext/module/attribute_accessors.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/module/attribute_accessors.rb2
1 files changed, 2 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb b/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb
index be94ae1565..84acb629ad 100644
--- a/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb
+++ b/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb
@@ -4,6 +4,7 @@ class Module
def mattr_reader(*syms)
options = syms.extract_options!
syms.each do |sym|
+ raise NameError.new("invalid attribute name") unless sym =~ /^[_A-Za-z]\w*$/
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
@@#{sym} = nil unless defined? @@#{sym}
@@ -25,6 +26,7 @@ class Module
def mattr_writer(*syms)
options = syms.extract_options!
syms.each do |sym|
+ raise NameError.new("invalid attribute name") unless sym =~ /^[_A-Za-z]\w*$/
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
def self.#{sym}=(obj)
@@#{sym} = obj