[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

BUG: small glitch in Net:HTTP when adding custom headers

Wejn

11/27/2004 12:39:00 AM

Hi,

today I was toying a bit with Net:HTTP and found small glitch
in HTTPGenericRequest#initialize ... line 1106 reads:

@header[key] = v.strip

which fails on NoMethodError when value of added header is not
String (it was triggered by Fixnum in my case).

In my opinion it should be:

@header[key] = v.to_s.strip

Am I right?

Regards,
W.

PS:

wejn@ns ~ $ ruby --version
ruby 1.8.2 (2004-11-06) [i686-linux]

wejn@ns ~ $ fgrep '$Id' /usr/lib/ruby/1.8/net/http.rb
# $Id: http.rb,v 1.100.2.6 2004/04/18 23:20:32 nobu Exp $
--
# Michal Safranek, email:
a=(("a".."z").to_a+["@","."]);p(("%b"%[0x645bbb83a6a496]
).scan(/...../).map{|x|a[Integer("0b"+x)]}.join.reverse)


2 Answers

Minero Aoki

11/27/2004 6:29:00 AM

0

Sam Roberts

11/27/2004 4:28:00 PM

0

Quoteing aamine@loveruby.net, on Sat, Nov 27, 2004 at 03:28:50PM +0900:
> Hi,
>
> In mail "BUG: small glitch in Net:HTTP when adding custom headers"
> Michal <lists+rubytalk@box.cz> wrote:
>
> > today I was toying a bit with Net:HTTP and found small glitch
> > in HTTPGenericRequest#initialize ... line 1106 reads:
> >
> > @header[key] = v.strip
> >
> > which fails on NoMethodError when value of added header is not
> > String (it was triggered by Fixnum in my case).
>
> I think this is the right behavior.
> An header field is a String, you should provide a String.
> Instant #to_s call will hide some kind of bugs (e.g. nil).

Yes, but #to_str would not hide a nil bug:

irb(main):002:0> nil.to_str
NoMethodError: undefined method `to_str' for nil:NilClass
from (irb):2

Also, when you get a NoMethodError saying there is no #to_str you will
think "oops, i should have passed a String", but when you get a
NoMethodError of #strip you might instead have to search the Net::HTTP
code trying to find out what was expected.

These are my thoughts... I always call #to_XXX on my args, because I am
tired of searching through library code trying to find what went wrong
(wrong in my code, of course, but it can show up much later if the
library just stores the object and doesn't use it right away).

Cheers,
Sam