From: Tanaka Akira Date: 2010-09-12T02:30:39+09:00 Subject: [ruby-core:32325] Re: [Ruby 1.8-Bug#3788] URI cannot parse IPv6 addresses propertly 2010/9/10 Marcus Rueckert : > doesnt that mean you will need to fix all of the users of the function? > with my net/http example above you can somewhat control it. All occurrences of URI::Generic#host should be examined. I guess there may be usages which needs the brackets. At least, one of the use in URI::Generic#find_proxy (defined in open-uri.rb) is not clear which is suitable between the brackets are removed or not. % svn diff --diff-cmd diff -x '-u -p' Index: lib/open-uri.rb =================================================================== --- lib/open-uri.rb (revision 29207) +++ lib/open-uri.rb (working copy) @@ -263,17 +263,17 @@ module OpenURI # HTTP or HTTPS if proxy if proxy_user && proxy_pass - klass = Net::HTTP::Proxy(proxy_uri.host, proxy_uri.port, proxy_user, proxy_pass) + klass = Net::HTTP::Proxy(proxy_uri.hostname, proxy_uri.port, proxy_user, proxy_pass) else - klass = Net::HTTP::Proxy(proxy_uri.host, proxy_uri.port) + klass = Net::HTTP::Proxy(proxy_uri.hostname, proxy_uri.port) end end - target_host = target.host + target_host = target.hostname target_port = target.port request_uri = target.request_uri else # FTP over HTTP proxy - target_host = proxy_uri.host + target_host = proxy_uri.hostname target_port = proxy_uri.port request_uri = target.to_s if proxy_user && proxy_pass @@ -736,10 +736,10 @@ module URI proxy_uri = ENV[name] || ENV[name.upcase] end - if proxy_uri && self.host + if proxy_uri && self.hostname require 'socket' begin - addr = IPSocket.getaddress(self.host) + addr = IPSocket.getaddress(self.hostname) proxy_uri = nil if /\A127\.|\A::1\z/ =~ addr rescue SocketError end @@ -804,7 +804,7 @@ module URI # The access sequence is defined by RFC 1738 ftp = Net::FTP.new - ftp.connect(self.host, self.port) + ftp.connect(self.hostname, self.port) ftp.passive = true if !options[:ftp_active_mode] # todo: extract user/passwd from .netrc. user = 'anonymous' Index: lib/net/http.rb =================================================================== --- lib/net/http.rb (revision 29207) +++ lib/net/http.rb (working copy) @@ -64,7 +64,7 @@ module Net #:nodoc: # require 'uri' # # url = URI.parse('http://www.example.com/index.html') - # res = Net::HTTP.start(url.host, url.port) {|http| + # res = Net::HTTP.start(url.hostname, url.port) {|http| # http.get('/index.html') # } # puts res.body @@ -75,7 +75,7 @@ module Net #:nodoc: # # url = URI.parse('http://www.example.com/index.html') # req = Net::HTTP::Get.new(url.path) - # res = Net::HTTP.start(url.host, url.port) {|http| + # res = Net::HTTP.start(url.hostname, url.port) {|http| # http.request(req) # } # puts res.body @@ -101,7 +101,7 @@ module Net #:nodoc: # req = Net::HTTP::Post.new(url.path) # req.basic_auth 'jack', 'pass' # req.set_form_data({'from' => '2005-01-01', 'to' => '2005-03-31'}, ';') - # res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) } + # res = Net::HTTP.new(url.hostname, url.port).start {|http| http.request(req) } # case res # when Net::HTTPSuccess, Net::HTTPRedirection # # OK @@ -390,7 +390,7 @@ module Net #:nodoc: } else uri = uri_or_host - new(uri.host, uri.port).start {|http| + new(uri.hostname, uri.port).start {|http| return http.request_get(uri.request_uri, &block) } end @@ -415,7 +415,7 @@ module Net #:nodoc: req = Post.new(url.path) req.form_data = params req.basic_auth url.user, url.password if url.user - new(url.host, url.port).start {|http| + new(url.hostname, url.port).start {|http| http.request(req) } end -- Tanaka Akira