Project

General

Profile

Bug #12422

CSV.Table.== fails to check object type

Added by robotfelix (Felix Kenton) almost 3 years ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]
[ruby-core:75707]

Description

CSV::Table's equality method presumes it is comparing another CSV::Table. It fails when the object to be compared doesn't support the table method.

This is more or less the same issue as reported and fixed in Bug #7528 (https://bugs.ruby-lang.org/issues/7528).

Test Case

require 'csv'
CSV.parse("test", headers: true) == nil
# => NoMethodError: undefined method `table' for nil:NilClass

Suggested Patch

Following the implementation used in CSV::Row, a suggested patch would be:

def ==(other)
  return @table == other.table if other.is_a? CSV::Table
  @table == other
end

Associated revisions

Revision 20aed449
Added by hsbt (Hiroshi SHIBATA) over 1 year ago

Fixed equality method fails when given the object that doesn't support table method.

[Bug #12422][ruby-core:75707]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59641 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 59641
Added by hsbt (Hiroshi SHIBATA) over 1 year ago

Fixed equality method fails when given the object that doesn't support table method.

[Bug #12422][ruby-core:75707]

Revision 59641
Added by hsbt (Hiroshi SHIBATA) over 1 year ago

Fixed equality method fails when given the object that doesn't support table method.

[Bug #12422][ruby-core:75707]

Revision 59641
Added by hsbt (Hiroshi SHIBATA) over 1 year ago

Fixed equality method fails when given the object that doesn't support table method.

[Bug #12422][ruby-core:75707]

History

Updated by nobu (Nobuyoshi Nakada) almost 3 years ago

  • Description updated (diff)
  • Status changed from Open to Assigned
  • Assignee set to JEG2 (James Gray)
  • Backport changed from 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN to 2.1: REQUIRED, 2.2: REQUIRED, 2.3: REQUIRED

Updated by hsbt (Hiroshi SHIBATA) over 1 year ago

  • Assignee changed from JEG2 (James Gray) to hsbt (Hiroshi SHIBATA)
#3

Updated by hsbt (Hiroshi SHIBATA) over 1 year ago

  • Status changed from Assigned to Closed

Applied in changeset trunk|r59641.


Fixed equality method fails when given the object that doesn't support table method.

[Bug #12422][ruby-core:75707]

Also available in: Atom PDF