[stdlib] [bug] nice exception in Net::HTTP::HTTPHeader

U

Ustalov Dmitry

hello.

method initialize_http_header() of the Net::HTTP::HTTPHeader doesn't
check the type of the 'value', and crashes with exception:
---8<---
/usr/lib/ruby/1.8/net/http.rb:1142:in `initialize_http_header':
undefined method `strip' for 1.43:Float (NoMethodError)
from /usr/lib/ruby/1.8/net/http.rb:1140:in `each'
from /usr/lib/ruby/1.8/net/http.rb:1140:in
`initialize_http_header'
from /usr/lib/ruby/1.8/net/http.rb:1472:in `initialize'
from /usr/lib/ruby/1.8/net/http.rb:1588:in `initialize'
from /usr/lib/ruby/1.8/net/http.rb:845:in `new'
from /usr/lib/ruby/1.8/net/http.rb:845:in `post'
--->8---

I think, we need to cast any 'value' to String in the
initialize_http_header()
---8<---
def initialize_http_header(initheader)
@header = {}
return unless initheader
initheader.each do |key, value|
warn "net/http: warning: duplicated HTTP header: #{key}" if
key?(key) and $VERBOSE
@header[key.downcase] = [value.strip]
end
end
--->8---
Maybe, we should use 'value.to_s.strip' instead of 'value.strip'?

How to reproduce this bug:
---8<---
#!/usr/bin/env ruby

# resolve any URI
require 'uri'
url = URI.parse("http://paste.org.ru/") # put your favourite site
here!

# define the data
data = 'data=oops'

# prepare the request
require 'net/http'
http = Net::HTTP.new(url.host, url.port)

headers = {
'Content-Length' => data.size
}

resp = http.post(url.path, data, headers)
--->8---

My system is:
Fedora 8 (Werewolf) i386, ruby 1.8.6
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top