mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Regex fix for mattr_accessor validation
Change ^ and $ operators to \A and \z to prevent code injection after the line breaks
This commit is contained in:
parent
f78650d56e
commit
3005c25a36
2 changed files with 16 additions and 2 deletions
|
@ -53,7 +53,7 @@ class Module
|
|||
def mattr_reader(*syms)
|
||||
options = syms.extract_options!
|
||||
syms.each do |sym|
|
||||
raise NameError.new("invalid attribute name: #{sym}") unless sym =~ /^[_A-Za-z]\w*$/
|
||||
raise NameError.new("invalid attribute name: #{sym}") unless sym =~ /\A[_A-Za-z]\w*\z/
|
||||
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
||||
@@#{sym} = nil unless defined? @@#{sym}
|
||||
|
||||
|
@ -119,7 +119,7 @@ class Module
|
|||
def mattr_writer(*syms)
|
||||
options = syms.extract_options!
|
||||
syms.each do |sym|
|
||||
raise NameError.new("invalid attribute name: #{sym}") unless sym =~ /^[_A-Za-z]\w*$/
|
||||
raise NameError.new("invalid attribute name: #{sym}") unless sym =~ /\A[_A-Za-z]\w*\z/
|
||||
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
||||
@@#{sym} = nil unless defined? @@#{sym}
|
||||
|
||||
|
|
|
@ -69,6 +69,20 @@ class ModuleAttributeAccessorTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
assert_equal "invalid attribute name: 1nvalid", exception.message
|
||||
|
||||
exception = assert_raises NameError do
|
||||
Class.new do
|
||||
mattr_reader "valid_part\ninvalid_part"
|
||||
end
|
||||
end
|
||||
assert_equal "invalid attribute name: valid_part\ninvalid_part", exception.message
|
||||
|
||||
exception = assert_raises NameError do
|
||||
Class.new do
|
||||
mattr_writer "valid_part\ninvalid_part"
|
||||
end
|
||||
end
|
||||
assert_equal "invalid attribute name: valid_part\ninvalid_part", exception.message
|
||||
end
|
||||
|
||||
def test_should_use_default_value_if_block_passed
|
||||
|
|
Loading…
Reference in a new issue