Project

General

Profile

Actions

Bug #10857

closed

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

Added by sclausson (Shayne Clausson) almost 7 years ago. Updated almost 7 years ago.

Status:
Closed
Priority:
Normal
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

Updated by nobu (Nobuyoshi Nakada) almost 7 years ago

  • Description updated (diff)
  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN to 2.0.0: DONTNEED, 2.1: REQUIRED, 2.2: REQUIRED
Actions #2

Updated by nobu (Nobuyoshi Nakada) almost 7 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

Applied in changeset r49620.


resolv.rb: fix equality

  • lib/resolv.rb (Resolv::DNS::Resource#==, #hash): elements returned by Kernel#instance_variables are Symbols now. [ruby-core:68128] [Bug #10857]

Updated by naruse (Yui NARUSE) almost 7 years ago

  • Backport changed from 2.0.0: DONTNEED, 2.1: REQUIRED, 2.2: REQUIRED to 2.0.0: DONTNEED, 2.1: REQUIRED, 2.2: DONE

ruby_2_2 r49627 merged revision(s) 49620.

Updated by usa (Usaku NAKAMURA) almost 7 years ago

  • Backport changed from 2.0.0: DONTNEED, 2.1: REQUIRED, 2.2: DONE to 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: DONE

Updated by nagachika (Tomoyuki Chikanaga) almost 7 years ago

  • Backport changed from 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: DONE to 2.0.0: REQUIRED, 2.1: DONE, 2.2: DONE

Backported into ruby_2_1 at r49628.

Updated by usa (Usaku NAKAMURA) almost 7 years ago

  • Backport changed from 2.0.0: REQUIRED, 2.1: DONE, 2.2: DONE to 2.0.0: DONE, 2.1: DONE, 2.2: DONE

ruby_2_0_0 r49639 merged revision(s) 49620.

Actions

Also available in: Atom PDF