Project

General

Profile

Actions

Bug #10857

closed

Resolv::DNS::Resource ==() method incorrectly returns false due to TTL attrib

Added by sclausson (Shayne Clausson) about 9 years ago. Updated about 9 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.3p545 (2014-02-24) [i386-mingw32]
[ruby-core:68128]

Description

require 'resolv'

resolver = Resolv::DNS.new(:nameserver => ['8.8.8.8'],
                :search => [],
                :ndots => 1)

hosts = resolver.getresources('ruby.org', Resolv::DNS::Resource::IN::A)
returned_record = hosts.first

a = Resolv::DNS::Resource::IN::A

#create an identical record
new_record = a.new(returned_record.address)

new_record == returned_record
=>false #but should return true

#If I change this
class Resolv::DNS::Resource
def ==(other) # :nodoc:
        return false unless self.class == other.class
        s_ivars = self.instance_variables
        s_ivars.sort!
        **s_ivars.delete "@ttl"**
        o_ivars = other.instance_variables
        o_ivars.sort!
        **o_ivars.delete "@ttl"**
        return s_ivars == o_ivars &&
          s_ivars.collect {|name| self.instance_variable_get name} ==
            o_ivars.collect {|name| other.instance_variable_get name}
      end
end

#To this
class Resolv::DNS::Resource
def ==(other) # :nodoc:
        return false unless self.class == other.class
        s_ivars = self.instance_variables
        s_ivars.sort!
        **s_ivars.delete(:@ttl)**
        o_ivars = other.instance_variables
        o_ivars.sort!
        **o_ivars.delete(:@ttl)**
        return s_ivars == o_ivars &&
          s_ivars.collect {|name| self.instance_variable_get name} ==
            o_ivars.collect {|name| other.instance_variable_get name}
      end
end

new_record == returned_record
=>true
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0