Guard for the ftp protocol feature of OpenURI

This commit is contained in:
Hiroshi SHIBATA 2021-05-26 20:18:46 +09:00
Родитель b8dcad8d32
Коммит 350bc29107
2 изменённых файлов: 134 добавлений и 123 удалений

Просмотреть файл

@ -750,7 +750,12 @@ module URI
OpenURI.open_http(buf, self, proxy, options)
return
end
begin
require 'net/ftp'
rescue LoadError
abort "net/ftp is not found. You may need to `gem install net-ftp` to install net/ftp."
end
path = self.path
path = path.sub(%r{\A/}, '%2F') # re-encode the beginning slash because uri library decodes it.

Просмотреть файл

@ -703,6 +703,9 @@ class TestOpenURI < Test::Unit::TestCase
# 192.0.2.0/24 is TEST-NET. [RFC3330]
begin
require 'net/ftp'
def test_ftp_invalid_request
assert_raise(ArgumentError) { URI("ftp://127.0.0.1/").read }
assert_raise(ArgumentError) { URI("ftp://127.0.0.1/a%0Db").read }
@ -841,6 +844,9 @@ class TestOpenURI < Test::Unit::TestCase
end
}
end
rescue LoadError
# net-ftp is the bundled gems at Ruby 3.1
end
def test_ftp_over_http_proxy
TCPServer.open("127.0.0.1", 0) {|proxy_serv|