Project

General

Profile

Actions

Bug #7528

closed

CSV.== fails to check object type

Added by SteveW (Stephen Wattam) about 12 years ago. Updated about 12 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux]
Backport:
[ruby-core:50636]

Description

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

/usr/lib/ruby/1.9.1/csv.rb:478:in ==': undefined method row' for nil:NilClass (NoMethodError)
from test.rb:7:in `'


Files

test.rb (256 Bytes) test.rb Simple test case using nil as the non-row value. SteveW (Stephen Wattam), 12/07/2012 12:04 AM
csv.rb.patch (121 Bytes) csv.rb.patch SteveW (Stephen Wattam), 12/07/2012 10:42 PM

Updated by SteveW (Stephen Wattam) about 12 years ago

This seems to fix it:

478c478,479
<       @row == other.row
---
>       return @row == other.row if other.class == CSV::Row
>       @row == other

Updated by Anonymous about 12 years ago

It would probably be better to perform an is_a? check rather than
checking the class of the other object.

Updated by SteveW (Stephen Wattam) about 12 years ago

I concur. Patch attached for easy application.

It's probably worth noting that the current, unpatched, behaviour seems to break foreach too.

Updated by drbrain (Eric Hodel) about 12 years ago

  • Category set to lib
  • Status changed from Open to Assigned
  • Assignee set to JEG2 (James Gray)
  • Target version set to 2.0.0
Actions #5

Updated by JEG2 (James Gray) about 12 years ago

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

This issue was solved with changeset r38265.
Stephen, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • lib/csv.rb: A fix for row comparison by Stephen Wattam. [Bug #7528]

Updated by zzak (zzak _) about 12 years ago

James, I think your editor may have committed a bunch of whitespace changes

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0