зеркало из https://github.com/github/ruby.git
* lib/resolv.rb (Resolv::IPv4::Regex): make it only accept 0 to 255.
[ruby-core:29501] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27389 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
e70a308c75
Коммит
20a6e94e47
|
@ -1,3 +1,8 @@
|
|||
Sun Apr 18 18:07:47 2010 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* lib/resolv.rb (Resolv::IPv4::Regex): make it only accept 0 to 255.
|
||||
[ruby-core:29501]
|
||||
|
||||
Sun Apr 18 12:48:51 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* parse.y (parser_yylex): seems like a symbol-literal when spaces
|
||||
|
|
|
@ -2110,7 +2110,11 @@ class Resolv
|
|||
##
|
||||
# Regular expression IPv4 addresses must match.
|
||||
|
||||
Regex = /\A(\d+)\.(\d+)\.(\d+)\.(\d+)\z/
|
||||
Regex256 = /0
|
||||
|1(?:[0-9][0-9]?)?
|
||||
|2(?:[0-4][0-9]?|5[0-5]?|[6-9])?
|
||||
|[3-9][0-9]?/x
|
||||
Regex = /\A(#{Regex256})\.(#{Regex256})\.(#{Regex256})\.(#{Regex256})\z/
|
||||
|
||||
def self.create(arg)
|
||||
case arg
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
require 'test/unit'
|
||||
require 'resolv'
|
||||
require 'socket'
|
||||
|
||||
class TestResolvAddr < Test::Unit::TestCase
|
||||
def test_invalid_ipv4_address
|
||||
assert_not_match(Resolv::IPv4::Regex, "1.2.3.256", "[ruby-core:29501]")
|
||||
1000.times {|i|
|
||||
if i < 256
|
||||
assert_match(Resolv::IPv4::Regex, "#{i}.#{i}.#{i}.#{i}")
|
||||
else
|
||||
assert_not_match(Resolv::IPv4::Regex, "#{i}.#{i}.#{i}.#{i}")
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
Загрузка…
Ссылка в новой задаче