ruby-changes:50556
From: naruse <ko1@a...>
Date: Fri, 9 Mar 2018 01:08:06 +0900 (JST)
Subject: [ruby-changes:50556] naruse:r62698 (trunk): Raise ArgumentError if host component is nil
naruse 2018-03-09 01:07:54 +0900 (Fri, 09 Mar 2018) New Revision: 62698 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62698 Log: Raise ArgumentError if host component is nil From: oss92 <mohamed.o.alnagdy@g...> fix https://github.com/ruby/ruby/pull/1278 Modified files: trunk/lib/net/http/generic_request.rb trunk/test/net/http/test_http_request.rb Index: test/net/http/test_http_request.rb =================================================================== --- test/net/http/test_http_request.rb (revision 62697) +++ test/net/http/test_http_request.rb (revision 62698) @@ -65,6 +65,18 @@ class HTTPRequestTest < Test::Unit::Test https://github.com/ruby/ruby/blob/trunk/test/net/http/test_http_request.rb#L65 'Bug #7381 - do not decode content if the user overrides' end if Net::HTTP::HAVE_ZLIB + def test_initialize_GET_uri + req = Net::HTTP::Get.new(URI("http://example.com/foo")) + assert_equal "/foo", req.path + assert_equal "example.com", req['Host'] + + req = Net::HTTP::Get.new(URI("https://example.com/foo")) + assert_equal "/foo", req.path + assert_equal "example.com", req['Host'] + + assert_raise(ArgumentError){ Net::HTTP::Get.new(URI("urn:ietf:rfc:7231")) } + end + def test_header_set req = Net::HTTP::Get.new '/' Index: lib/net/http/generic_request.rb =================================================================== --- lib/net/http/generic_request.rb (revision 62697) +++ lib/net/http/generic_request.rb (revision 62698) @@ -14,6 +14,8 @@ class Net::HTTPGenericRequest https://github.com/ruby/ruby/blob/trunk/lib/net/http/generic_request.rb#L14 @response_has_body = resbody if URI === uri_or_path then + raise ArgumentError, "not an HTTP URI" unless URI::HTTP === uri_or_path + raise ArgumentError, "no host component for URI" unless uri_or_path.hostname @uri = uri_or_path.dup host = @uri.hostname.dup host << ":".freeze << @uri.port.to_s if @uri.port != @uri.default_port -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/