Forum: Ruby-core [ruby-trunk - Bug #7528][Open] CSV.== fails to check object type

Posted by SteveW (Stephen Wattam) (Guest)
on 2012-12-06 16:04
(Received via mailing list)
Issue #7528 has been reported by SteveW (Stephen Wattam).

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

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 method `row' for 
nil:NilClass (NoMethodError)
  from test.rb:7:in `<main>'
Posted by SteveW (Stephen Wattam) (Guest)
on 2012-12-07 12:56
(Received via mailing list)
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 method `row' for 
nil:NilClass (NoMethodError)
  from test.rb:7:in `<main>'
Posted by Charlie Somerville (Guest)
on 2012-12-07 13:07
(Received via mailing list)
=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>
Posted by SteveW (Stephen Wattam) (Guest)
on 2012-12-07 14:43
(Received via mailing list)
Issue #7528 has been updated by SteveW (Stephen Wattam).

File csv.rb.patch added

I concur.  Patch attached for easy application.

It's probably worth noting that the current, unpatched, behaviour seems 
to break foreach too.
----------------------------------------
Bug #7528: CSV.== fails to check object type
https://bugs.ruby-lang.org/issues/7528#change-34505

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 method `row' for 
nil:NilClass (NoMethodError)
  from test.rb:7:in `<main>'
Posted by drbrain (Eric Hodel) (Guest)
on 2012-12-07 18:07
(Received via mailing list)
Issue #7528 has been updated by drbrain (Eric Hodel).

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


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

Author: SteveW (Stephen Wattam)
Status: Assigned
Priority: Normal
Assignee: JEG2 (James Gray)
Category: lib
Target version: 2.0.0
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 method `row' for 
nil:NilClass (NoMethodError)
  from test.rb:7:in `<main>'
Posted by zzak (Zachary Scott) (Guest)
on 2012-12-07 18:53
(Received via mailing list)
Issue #7528 has been updated by zzak (Zachary Scott).


James, I think your editor may have committed a bunch of whitespace 
changes
----------------------------------------
Bug #7528: CSV.== fails to check object type
https://bugs.ruby-lang.org/issues/7528#change-34516

Author: SteveW (Stephen Wattam)
Status: Closed
Priority: Normal
Assignee: JEG2 (James Gray)
Category: lib
Target version: 2.0.0
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 method `row' for 
nil:NilClass (NoMethodError)
  from test.rb:7:in `<main>'
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.