зеркало из https://github.com/github/ruby.git
IPAddr#== and IPAddr#<=> no longer raise an exception if coercion fails
* lib/ipaddr.rb (IPAddr#==): If coercion fails, return false instead of passing through the exception. [ruby-core:77451] [Bug #12799] * lib/ipaddr.rb (IPAddr#<=>): If coercion fails, return nil instead of passing through the exception. [ruby-core:77451] [Bug #12799] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56594 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
9cbd6ee097
Коммит
2d8841791f
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
||||||
|
Sat Nov 5 22:50:13 2016 Akinori MUSHA <knu@iDaemons.org>
|
||||||
|
|
||||||
|
* lib/ipaddr.rb (IPAddr#==): If coercion fails, return false
|
||||||
|
instead of passing through the exception. [ruby-core:77451]
|
||||||
|
[Bug #12799]
|
||||||
|
|
||||||
|
* lib/ipaddr.rb (IPAddr#<=>): If coercion fails, return nil
|
||||||
|
instead of passing through the exception. [ruby-core:77451]
|
||||||
|
[Bug #12799]
|
||||||
|
|
||||||
Sat Nov 5 22:11:33 2016 Kazuki Tsujimoto <kazuki@callcc.net>
|
Sat Nov 5 22:11:33 2016 Kazuki Tsujimoto <kazuki@callcc.net>
|
||||||
|
|
||||||
* vm_trace.c (tracepoint_attr_callee_id, rb_tracearg_callee_id):
|
* vm_trace.c (tracepoint_attr_callee_id, rb_tracearg_callee_id):
|
||||||
|
|
5
NEWS
5
NEWS
|
@ -181,6 +181,11 @@ with all sufficient information, see the ChangeLog file or Redmine
|
||||||
|
|
||||||
* Add a liberal_parsing option. [Feature #11839]
|
* Add a liberal_parsing option. [Feature #11839]
|
||||||
|
|
||||||
|
* IPAddr
|
||||||
|
|
||||||
|
* IPAddr#== and IPAddr#<=> no longer raise an exception if coercion fails.
|
||||||
|
[Bug #12799]
|
||||||
|
|
||||||
* Logger
|
* Logger
|
||||||
|
|
||||||
* Allow specifying logger parameters in constructor such
|
* Allow specifying logger parameters in constructor such
|
||||||
|
|
|
@ -149,7 +149,10 @@ class IPAddr
|
||||||
# Returns true if two ipaddrs are equal.
|
# Returns true if two ipaddrs are equal.
|
||||||
def ==(other)
|
def ==(other)
|
||||||
other = coerce_other(other)
|
other = coerce_other(other)
|
||||||
return @family == other.family && @addr == other.to_i
|
rescue
|
||||||
|
false
|
||||||
|
else
|
||||||
|
@family == other.family && @addr == other.to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a new ipaddr built by masking IP address with the given
|
# Returns a new ipaddr built by masking IP address with the given
|
||||||
|
@ -335,10 +338,10 @@ class IPAddr
|
||||||
# Compares the ipaddr with another.
|
# Compares the ipaddr with another.
|
||||||
def <=>(other)
|
def <=>(other)
|
||||||
other = coerce_other(other)
|
other = coerce_other(other)
|
||||||
|
rescue
|
||||||
return nil if other.family != @family
|
nil
|
||||||
|
else
|
||||||
return @addr <=> other.to_i
|
@addr <=> other.to_i if other.family == @family
|
||||||
end
|
end
|
||||||
include Comparable
|
include Comparable
|
||||||
|
|
||||||
|
|
|
@ -169,6 +169,8 @@ class TC_Operator < Test::Unit::TestCase
|
||||||
@a = IPAddr.new("3ffe:505:2::/48")
|
@a = IPAddr.new("3ffe:505:2::/48")
|
||||||
@b = IPAddr.new("0:0:0:1::")
|
@b = IPAddr.new("0:0:0:1::")
|
||||||
@c = IPAddr.new(IN6MASK32)
|
@c = IPAddr.new(IN6MASK32)
|
||||||
|
@inconvertible_range = 1..5
|
||||||
|
@inconvertible_string = "sometext"
|
||||||
end
|
end
|
||||||
alias set_up setup
|
alias set_up setup
|
||||||
|
|
||||||
|
@ -220,6 +222,13 @@ class TC_Operator < Test::Unit::TestCase
|
||||||
assert_equal(false, @a == IPAddr.new("3ffe:505:3::"))
|
assert_equal(false, @a == IPAddr.new("3ffe:505:3::"))
|
||||||
assert_equal(true, @a != IPAddr.new("3ffe:505:3::"))
|
assert_equal(true, @a != IPAddr.new("3ffe:505:3::"))
|
||||||
assert_equal(false, @a != IPAddr.new("3ffe:505:2::"))
|
assert_equal(false, @a != IPAddr.new("3ffe:505:2::"))
|
||||||
|
assert_equal(false, @a == @inconvertible_range)
|
||||||
|
assert_equal(false, @a == @inconvertible_string)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_compare
|
||||||
|
assert_equal(nil, @a <=> @inconvertible_range)
|
||||||
|
assert_equal(nil, @a <=> @inconvertible_string)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_mask
|
def test_mask
|
||||||
|
|
Загрузка…
Ссылка в новой задаче