Bug #7528

CSV.== fails to check object type

Added by Stephen Wattam over 2 years ago. Updated over 2 years ago.

[ruby-core:50636]
Status:Closed
Priority:Normal
Assignee:James Gray
ruby -v:ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux] Backport:

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 methodrow' for nil:NilClass (NoMethodError)
from test.rb:7:in `'

test.rb Magnifier - Simple test case using nil as the non-row value. (256 Bytes) Stephen Wattam, 12/07/2012 12:04 AM

csv.rb.patch Magnifier (121 Bytes) Stephen Wattam, 12/07/2012 10:42 PM

Associated revisions

Revision 38265
Added by James Gray over 2 years ago

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

Revision 38265
Added by James Gray over 2 years ago

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

History

#1 Updated by Stephen Wattam over 2 years ago

This seems to fix it:

478c478,479

< @row == other.row

  return @row == other.row if other.class == CSV::Row
  @row == other

#2 Updated by Charlie Somerville over 2 years ago

=begin
It would probably be better to perform an (({is_a?})) check rather than
checking the class of the other object.
=end
On Dec 7, 2012 10:56 PM, "SteveW (Stephen Wattam)" stephenwattam@gmail.com
wrote:

Issue #7528 has been updated by SteveW (Stephen Wattam).

This seems to fix it:

478c478,479

< @row == other.row

  return @row == other.row if other.class == CSV::Row
  @row == other

Bug #7528: CSV.== fails to check object type
https://bugs.ruby-lang.org/issues/7528#change-34502

Author: SteveW (Stephen Wattam)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux]

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 methodrow' for
nil:NilClass (NoMethodError)
from test.rb:7:in `'

http://bugs.ruby-lang.org/

#3 Updated by Stephen Wattam over 2 years ago

I concur. Patch attached for easy application.

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

#4 Updated by Eric Hodel over 2 years ago

  • Target version set to 2.0.0
  • Category set to lib
  • Status changed from Open to Assigned
  • Assignee set to James Gray

#5 Updated by James Gray over 2 years ago

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

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]

#6 Updated by Zachary Scott over 2 years ago

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

Also available in: Atom PDF