Project

General

Profile

Actions

Bug #12422

closed

CSV.Table.== fails to check object type

Added by robotfelix (Felix Kenton) almost 8 years ago. Updated over 6 years ago.

Status:
Closed
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
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0