Vendor uri gem in RubyGems
This commit is contained in:
parent
6bbbfb4629
commit
d64d0b5423
@ -59,7 +59,7 @@ class Gem::Commands::SourcesCommand < Gem::Command
|
||||
|
||||
say "#{source_uri} added to sources"
|
||||
end
|
||||
rescue URI::Error, ArgumentError
|
||||
rescue Gem::URI::Error, ArgumentError
|
||||
say "#{source_uri} is not a URI"
|
||||
terminate_interaction 1
|
||||
rescue Gem::RemoteFetcher::FetchError => e
|
||||
@ -81,7 +81,7 @@ Do you want to add this source?
|
||||
end
|
||||
|
||||
def check_rubygems_https(source_uri) # :nodoc:
|
||||
uri = URI source_uri
|
||||
uri = Gem::URI source_uri
|
||||
|
||||
if uri.scheme && uri.scheme.casecmp("http").zero? &&
|
||||
uri.host.casecmp("rubygems.org").zero?
|
||||
|
@ -93,8 +93,8 @@ module Gem::GemcutterUtilities
|
||||
end
|
||||
|
||||
if allowed_push_host
|
||||
allowed_host_uri = URI.parse(allowed_push_host)
|
||||
host_uri = URI.parse(self.host)
|
||||
allowed_host_uri = Gem::URI.parse(allowed_push_host)
|
||||
host_uri = Gem::URI.parse(self.host)
|
||||
|
||||
unless (host_uri.scheme == allowed_host_uri.scheme) && (host_uri.host == allowed_host_uri.host)
|
||||
alert_error "#{self.host.inspect} is not allowed by the gemspec, which only allows #{allowed_push_host.inspect}"
|
||||
@ -102,7 +102,7 @@ module Gem::GemcutterUtilities
|
||||
end
|
||||
end
|
||||
|
||||
uri = URI.parse "#{self.host}/#{path}"
|
||||
uri = Gem::URI.parse "#{self.host}/#{path}"
|
||||
response = request_with_otp(method, uri, &block)
|
||||
|
||||
if mfa_unauthorized?(response)
|
||||
@ -136,7 +136,7 @@ module Gem::GemcutterUtilities
|
||||
sign_in_host, scope: scope) do |request|
|
||||
request.basic_auth email, password
|
||||
request["OTP"] = otp if otp
|
||||
request.body = URI.encode_www_form({ api_key: api_key }.merge(update_scope_params))
|
||||
request.body = Gem::URI.encode_www_form({ api_key: api_key }.merge(update_scope_params))
|
||||
end
|
||||
|
||||
with_response response do |_resp|
|
||||
@ -176,7 +176,7 @@ module Gem::GemcutterUtilities
|
||||
sign_in_host, credentials: credentials, scope: scope) do |request|
|
||||
request.basic_auth email, password
|
||||
request["OTP"] = otp if otp
|
||||
request.body = URI.encode_www_form({ name: key_name }.merge(all_params))
|
||||
request.body = Gem::URI.encode_www_form({ name: key_name }.merge(all_params))
|
||||
end
|
||||
|
||||
with_response response do |resp|
|
||||
|
@ -51,7 +51,7 @@ module Gem::GemcutterUtilities
|
||||
request_line = socket.gets
|
||||
|
||||
method, req_uri, _protocol = request_line.split(" ")
|
||||
req_uri = URI.parse(req_uri)
|
||||
req_uri = Gem::URI.parse(req_uri)
|
||||
|
||||
responder = SocketResponder.new(socket)
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
# See LICENSE.txt for permissions.
|
||||
#++
|
||||
|
||||
require "uri"
|
||||
require_relative "vendor/uri/lib/uri"
|
||||
require_relative "../rubygems"
|
||||
|
||||
##
|
||||
@ -17,10 +17,10 @@ module Gem::LocalRemoteOptions
|
||||
# Allows Gem::OptionParser to handle HTTP URIs.
|
||||
|
||||
def accept_uri_http
|
||||
Gem::OptionParser.accept URI::HTTP do |value|
|
||||
Gem::OptionParser.accept Gem::URI::HTTP do |value|
|
||||
begin
|
||||
uri = URI.parse value
|
||||
rescue URI::InvalidURIError
|
||||
uri = Gem::URI.parse value
|
||||
rescue Gem::URI::InvalidURIError
|
||||
raise Gem::OptionParser::InvalidArgument, value
|
||||
end
|
||||
|
||||
@ -88,7 +88,7 @@ module Gem::LocalRemoteOptions
|
||||
def add_proxy_option
|
||||
accept_uri_http
|
||||
|
||||
add_option(:"Local/Remote", "-p", "--[no-]http-proxy [URL]", URI::HTTP,
|
||||
add_option(:"Local/Remote", "-p", "--[no-]http-proxy [URL]", Gem::URI::HTTP,
|
||||
"Use HTTP proxy for remote operations") do |value, options|
|
||||
options[:http_proxy] = value == false ? :no_proxy : value
|
||||
Gem.configuration[:http_proxy] = options[:http_proxy]
|
||||
@ -101,7 +101,7 @@ module Gem::LocalRemoteOptions
|
||||
def add_source_option
|
||||
accept_uri_http
|
||||
|
||||
add_option(:"Local/Remote", "-s", "--source URL", URI::HTTP,
|
||||
add_option(:"Local/Remote", "-s", "--source URL", Gem::URI::HTTP,
|
||||
"Append URL to list of remote gem sources") do |source, options|
|
||||
source << "/" unless source.end_with?("/")
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
#
|
||||
|
||||
require_relative '../../../net-protocol/lib/net/protocol'
|
||||
require 'uri'
|
||||
require_relative '../../../vendor/uri/lib/uri'
|
||||
require_relative '../../../resolv/lib/resolv'
|
||||
autoload :OpenSSL, 'openssl'
|
||||
|
||||
@ -106,20 +106,20 @@ module Gem::Net #:nodoc:
|
||||
# It consists of some or all of: scheme, hostname, path, query, and fragment;
|
||||
# see {URI syntax}[https://en.wikipedia.org/wiki/Uniform_Resource_Identifier#Syntax].
|
||||
#
|
||||
# A Ruby {URI::Generic}[rdoc-ref:URI::Generic] object
|
||||
# A Ruby {Gem::URI::Generic}[https://docs.ruby-lang.org/en/master/Gem/URI/Generic.html] object
|
||||
# represents an internet URI.
|
||||
# It provides, among others, methods
|
||||
# +scheme+, +hostname+, +path+, +query+, and +fragment+.
|
||||
#
|
||||
# === Schemes
|
||||
#
|
||||
# An internet \URI has
|
||||
# An internet \Gem::URI has
|
||||
# a {scheme}[https://en.wikipedia.org/wiki/List_of_URI_schemes].
|
||||
#
|
||||
# The two schemes supported in \Gem::Net::HTTP are <tt>'https'</tt> and <tt>'http'</tt>:
|
||||
#
|
||||
# uri.scheme # => "https"
|
||||
# URI('http://example.com').scheme # => "http"
|
||||
# Gem::URI('http://example.com').scheme # => "http"
|
||||
#
|
||||
# === Hostnames
|
||||
#
|
||||
@ -146,8 +146,8 @@ module Gem::Net #:nodoc:
|
||||
#
|
||||
# _uri = uri.dup
|
||||
# params = {userId: 1, completed: false}
|
||||
# _uri.query = URI.encode_www_form(params)
|
||||
# _uri # => #<URI::HTTPS https://jsonplaceholder.typicode.com?userId=1&completed=false>
|
||||
# _uri.query = Gem::URI.encode_www_form(params)
|
||||
# _uri # => #<Gem::URI::HTTPS https://jsonplaceholder.typicode.com?userId=1&completed=false>
|
||||
# Gem::Net::HTTP.get(_uri)
|
||||
#
|
||||
# === Fragments
|
||||
@ -273,7 +273,7 @@ module Gem::Net #:nodoc:
|
||||
# # You should choose a better exception.
|
||||
# raise ArgumentError, 'Too many HTTP redirects' if limit == 0
|
||||
#
|
||||
# res = Gem::Net::HTTP.get_response(URI(uri))
|
||||
# res = Gem::Net::HTTP.get_response(Gem::URI(uri))
|
||||
# case res
|
||||
# when Gem::Net::HTTPSuccess # Any success class.
|
||||
# res
|
||||
@ -327,9 +327,9 @@ module Gem::Net #:nodoc:
|
||||
#
|
||||
# Or if you simply want to make a GET request, you may pass in a URI
|
||||
# object that has an \HTTPS URL. \Gem::Net::HTTP automatically turns on TLS
|
||||
# verification if the URI object has a 'https' URI scheme:
|
||||
# verification if the URI object has a 'https' :URI scheme:
|
||||
#
|
||||
# uri # => #<URI::HTTPS https://jsonplaceholder.typicode.com/>
|
||||
# uri # => #<Gem::URI::HTTPS https://jsonplaceholder.typicode.com/>
|
||||
# Gem::Net::HTTP.get(uri)
|
||||
#
|
||||
# == Proxy Server
|
||||
@ -371,9 +371,9 @@ module Gem::Net #:nodoc:
|
||||
# === Proxy Using '<tt>ENV['http_proxy']</tt>'
|
||||
#
|
||||
# When environment variable <tt>'http_proxy'</tt>
|
||||
# is set to a \URI string,
|
||||
# is set to a \Gem::URI string,
|
||||
# the returned +http+ will have the server at that URI as its proxy;
|
||||
# note that the \URI string must have a protocol
|
||||
# note that the \Gem::URI string must have a protocol
|
||||
# such as <tt>'http'</tt> or <tt>'https'</tt>:
|
||||
#
|
||||
# ENV['http_proxy'] = 'http://example.com'
|
||||
@ -386,7 +386,7 @@ module Gem::Net #:nodoc:
|
||||
# http.proxy_user # => nil
|
||||
# http.proxy_pass # => nil
|
||||
#
|
||||
# The \URI string may include proxy username, password, and port number:
|
||||
# The \Gem::URI string may include proxy username, password, and port number:
|
||||
#
|
||||
# ENV['http_proxy'] = 'http://pname:ppass@example.com:8000'
|
||||
# http = Gem::Net::HTTP.new(hostname)
|
||||
@ -790,7 +790,7 @@ module Gem::Net #:nodoc:
|
||||
#
|
||||
# With URI object +uri+ and optional hash argument +headers+:
|
||||
#
|
||||
# uri = URI('https://jsonplaceholder.typicode.com/todos/1')
|
||||
# uri = Gem::URI('https://jsonplaceholder.typicode.com/todos/1')
|
||||
# headers = {'Content-type' => 'application/json; charset=UTF-8'}
|
||||
# Gem::Net::HTTP.get(uri, headers)
|
||||
#
|
||||
@ -1074,7 +1074,7 @@ module Gem::Net #:nodoc:
|
||||
elsif p_addr == :ENV then
|
||||
http.proxy_from_env = true
|
||||
else
|
||||
if p_addr && p_no_proxy && !URI::Generic.use_proxy?(address, address, port, p_no_proxy)
|
||||
if p_addr && p_no_proxy && !Gem::URI::Generic.use_proxy?(address, address, port, p_no_proxy)
|
||||
p_addr = nil
|
||||
p_port = nil
|
||||
end
|
||||
@ -1796,7 +1796,7 @@ module Gem::Net #:nodoc:
|
||||
# The proxy URI determined from the environment for this connection.
|
||||
def proxy_uri # :nodoc:
|
||||
return if @proxy_uri == false
|
||||
@proxy_uri ||= URI::HTTP.new(
|
||||
@proxy_uri ||= Gem::URI::HTTP.new(
|
||||
"http", nil, address, port, nil, nil, nil, nil, nil
|
||||
).find_proxy || false
|
||||
@proxy_uri || nil
|
||||
|
@ -17,10 +17,10 @@ class Gem::Net::HTTPGenericRequest
|
||||
@request_has_body = reqbody
|
||||
@response_has_body = resbody
|
||||
|
||||
if URI === uri_or_path then
|
||||
raise ArgumentError, "not an HTTP URI" unless URI::HTTP === uri_or_path
|
||||
if Gem::URI === uri_or_path then
|
||||
raise ArgumentError, "not an HTTP Gem::URI" unless Gem::URI::HTTP === uri_or_path
|
||||
hostname = uri_or_path.hostname
|
||||
raise ArgumentError, "no host component for URI" unless (hostname && hostname.length > 0)
|
||||
raise ArgumentError, "no host component for Gem::URI" unless (hostname && hostname.length > 0)
|
||||
@uri = uri_or_path.dup
|
||||
host = @uri.hostname.dup
|
||||
host << ":" << @uri.port.to_s if @uri.port != @uri.default_port
|
||||
@ -71,10 +71,10 @@ class Gem::Net::HTTPGenericRequest
|
||||
#
|
||||
attr_reader :path
|
||||
|
||||
# Returns the URI object for the request, or +nil+ if none:
|
||||
# Returns the Gem::URI object for the request, or +nil+ if none:
|
||||
#
|
||||
# Gem::Net::HTTP::Get.new(uri).uri
|
||||
# # => #<URI::HTTPS https://jsonplaceholder.typicode.com/>
|
||||
# # => #<Gem::URI::HTTPS https://jsonplaceholder.typicode.com/>
|
||||
# Gem::Net::HTTP::Get.new('example.com').uri # => nil
|
||||
#
|
||||
attr_reader :uri
|
||||
@ -213,10 +213,10 @@ class Gem::Net::HTTPGenericRequest
|
||||
|
||||
if ssl
|
||||
scheme = 'https'
|
||||
klass = URI::HTTPS
|
||||
klass = Gem::URI::HTTPS
|
||||
else
|
||||
scheme = 'http'
|
||||
klass = URI::HTTP
|
||||
klass = Gem::URI::HTTP
|
||||
end
|
||||
|
||||
if host = self['host']
|
||||
@ -225,7 +225,7 @@ class Gem::Net::HTTPGenericRequest
|
||||
else
|
||||
host = addr
|
||||
end
|
||||
# convert the class of the URI
|
||||
# convert the class of the Gem::URI
|
||||
if @uri.is_a?(klass)
|
||||
@uri.host = host
|
||||
@uri.port = port
|
||||
@ -286,7 +286,7 @@ class Gem::Net::HTTPGenericRequest
|
||||
def send_request_with_body_data(sock, ver, path, params)
|
||||
if /\Amultipart\/form-data\z/i !~ self.content_type
|
||||
self.content_type = 'application/x-www-form-urlencoded'
|
||||
return send_request_with_body(sock, ver, path, URI.encode_www_form(params))
|
||||
return send_request_with_body(sock, ver, path, Gem::URI.encode_www_form(params))
|
||||
end
|
||||
|
||||
opt = @form_option.dup
|
||||
|
@ -782,7 +782,7 @@ module Gem::Net::HTTPHeader
|
||||
# The resulting request is suitable for HTTP request +POST+ or +PUT+.
|
||||
#
|
||||
# Argument +params+ must be suitable for use as argument +enum+ to
|
||||
# {URI.encode_www_form}[https://docs.ruby-lang.org/en/master/URI.html#method-c-encode_www_form].
|
||||
# {Gem::URI.encode_www_form}[https://docs.ruby-lang.org/en/master/Gem::URI.html#method-c-encode_www_form].
|
||||
#
|
||||
# With only argument +params+ given,
|
||||
# sets the body to a URL-encoded string with the default separator <tt>'&'</tt>:
|
||||
@ -810,7 +810,7 @@ module Gem::Net::HTTPHeader
|
||||
#
|
||||
# Gem::Net::HTTPHeader#form_data= is an alias for Gem::Net::HTTPHeader#set_form_data.
|
||||
def set_form_data(params, sep = '&')
|
||||
query = URI.encode_www_form(params)
|
||||
query = Gem::URI.encode_www_form(params)
|
||||
query.gsub!(/&/, sep) if sep != '&'
|
||||
self.body = query
|
||||
self.content_type = 'application/x-www-form-urlencoded'
|
||||
|
@ -6,10 +6,10 @@
|
||||
#
|
||||
# == Creating a Request
|
||||
#
|
||||
# An request object may be created with either a URI or a string hostname:
|
||||
# An request object may be created with either a Gem::URI or a string hostname:
|
||||
#
|
||||
# require 'rubygems/net-http/lib/net/http'
|
||||
# uri = URI('https://jsonplaceholder.typicode.com/')
|
||||
# uri = Gem::URI('https://jsonplaceholder.typicode.com/')
|
||||
# req = Gem::Net::HTTP::Get.new(uri) # => #<Gem::Net::HTTP::Get GET>
|
||||
# req = Gem::Net::HTTP::Get.new(uri.hostname) # => #<Gem::Net::HTTP::Get GET>
|
||||
#
|
||||
|
@ -6,7 +6,7 @@
|
||||
# {HTTP method GET}[https://en.wikipedia.org/w/index.php?title=Hypertext_Transfer_Protocol#GET_method]:
|
||||
#
|
||||
# require 'rubygems/net-http/lib/net/http'
|
||||
# uri = URI('http://example.com')
|
||||
# uri = Gem::URI('http://example.com')
|
||||
# hostname = uri.hostname # => "example.com"
|
||||
# req = Gem::Net::HTTP::Get.new(uri) # => #<Gem::Net::HTTP::Get GET>
|
||||
# res = Gem::Net::HTTP.start(hostname) do |http|
|
||||
@ -38,7 +38,7 @@ end
|
||||
# {HTTP method HEAD}[https://en.wikipedia.org/w/index.php?title=Hypertext_Transfer_Protocol#HEAD_method]:
|
||||
#
|
||||
# require 'rubygems/net-http/lib/net/http'
|
||||
# uri = URI('http://example.com')
|
||||
# uri = Gem::URI('http://example.com')
|
||||
# hostname = uri.hostname # => "example.com"
|
||||
# req = Gem::Net::HTTP::Head.new(uri) # => #<Gem::Net::HTTP::Head HEAD>
|
||||
# res = Gem::Net::HTTP.start(hostname) do |http|
|
||||
@ -69,7 +69,7 @@ end
|
||||
# {HTTP method POST}[https://en.wikipedia.org/w/index.php?title=Hypertext_Transfer_Protocol#POST_method]:
|
||||
#
|
||||
# require 'rubygems/net-http/lib/net/http'
|
||||
# uri = URI('http://example.com')
|
||||
# uri = Gem::URI('http://example.com')
|
||||
# hostname = uri.hostname # => "example.com"
|
||||
# uri.path = '/posts'
|
||||
# req = Gem::Net::HTTP::Post.new(uri) # => #<Gem::Net::HTTP::Post POST>
|
||||
@ -104,7 +104,7 @@ end
|
||||
# {HTTP method PUT}[https://en.wikipedia.org/w/index.php?title=Hypertext_Transfer_Protocol#PUT_method]:
|
||||
#
|
||||
# require 'rubygems/net-http/lib/net/http'
|
||||
# uri = URI('http://example.com')
|
||||
# uri = Gem::URI('http://example.com')
|
||||
# hostname = uri.hostname # => "example.com"
|
||||
# uri.path = '/posts'
|
||||
# req = Gem::Net::HTTP::Put.new(uri) # => #<Gem::Net::HTTP::Put PUT>
|
||||
@ -134,7 +134,7 @@ end
|
||||
# {HTTP method DELETE}[https://en.wikipedia.org/w/index.php?title=Hypertext_Transfer_Protocol#DELETE_method]:
|
||||
#
|
||||
# require 'rubygems/net-http/lib/net/http'
|
||||
# uri = URI('http://example.com')
|
||||
# uri = Gem::URI('http://example.com')
|
||||
# hostname = uri.hostname # => "example.com"
|
||||
# uri.path = '/posts/1'
|
||||
# req = Gem::Net::HTTP::Delete.new(uri) # => #<Gem::Net::HTTP::Delete DELETE>
|
||||
@ -166,7 +166,7 @@ end
|
||||
# {HTTP method OPTIONS}[https://en.wikipedia.org/w/index.php?title=Hypertext_Transfer_Protocol#OPTIONS_method]:
|
||||
#
|
||||
# require 'rubygems/net-http/lib/net/http'
|
||||
# uri = URI('http://example.com')
|
||||
# uri = Gem::URI('http://example.com')
|
||||
# hostname = uri.hostname # => "example.com"
|
||||
# req = Gem::Net::HTTP::Options.new(uri) # => #<Gem::Net::HTTP::Options OPTIONS>
|
||||
# res = Gem::Net::HTTP.start(hostname) do |http|
|
||||
@ -197,7 +197,7 @@ end
|
||||
# {HTTP method TRACE}[https://en.wikipedia.org/w/index.php?title=Hypertext_Transfer_Protocol#TRACE_method]:
|
||||
#
|
||||
# require 'rubygems/net-http/lib/net/http'
|
||||
# uri = URI('http://example.com')
|
||||
# uri = Gem::URI('http://example.com')
|
||||
# hostname = uri.hostname # => "example.com"
|
||||
# req = Gem::Net::HTTP::Trace.new(uri) # => #<Gem::Net::HTTP::Trace TRACE>
|
||||
# res = Gem::Net::HTTP.start(hostname) do |http|
|
||||
@ -228,7 +228,7 @@ end
|
||||
# {HTTP method PATCH}[https://en.wikipedia.org/w/index.php?title=Hypertext_Transfer_Protocol#PATCH_method]:
|
||||
#
|
||||
# require 'rubygems/net-http/lib/net/http'
|
||||
# uri = URI('http://example.com')
|
||||
# uri = Gem::URI('http://example.com')
|
||||
# hostname = uri.hostname # => "example.com"
|
||||
# uri.path = '/posts'
|
||||
# req = Gem::Net::HTTP::Patch.new(uri) # => #<Gem::Net::HTTP::Patch PATCH>
|
||||
@ -266,7 +266,7 @@ end
|
||||
# {WebDAV method PROPFIND}[http://www.webdav.org/specs/rfc4918.html#METHOD_PROPFIND]:
|
||||
#
|
||||
# require 'rubygems/net-http/lib/net/http'
|
||||
# uri = URI('http://example.com')
|
||||
# uri = Gem::URI('http://example.com')
|
||||
# hostname = uri.hostname # => "example.com"
|
||||
# req = Gem::Net::HTTP::Propfind.new(uri) # => #<Gem::Net::HTTP::Propfind PROPFIND>
|
||||
# res = Gem::Net::HTTP.start(hostname) do |http|
|
||||
@ -289,7 +289,7 @@ end
|
||||
# {WebDAV method PROPPATCH}[http://www.webdav.org/specs/rfc4918.html#METHOD_PROPPATCH]:
|
||||
#
|
||||
# require 'rubygems/net-http/lib/net/http'
|
||||
# uri = URI('http://example.com')
|
||||
# uri = Gem::URI('http://example.com')
|
||||
# hostname = uri.hostname # => "example.com"
|
||||
# req = Gem::Net::HTTP::Proppatch.new(uri) # => #<Gem::Net::HTTP::Proppatch PROPPATCH>
|
||||
# res = Gem::Net::HTTP.start(hostname) do |http|
|
||||
@ -312,7 +312,7 @@ end
|
||||
# {WebDAV method MKCOL}[http://www.webdav.org/specs/rfc4918.html#METHOD_MKCOL]:
|
||||
#
|
||||
# require 'rubygems/net-http/lib/net/http'
|
||||
# uri = URI('http://example.com')
|
||||
# uri = Gem::URI('http://example.com')
|
||||
# hostname = uri.hostname # => "example.com"
|
||||
# req = Gem::Net::HTTP::Mkcol.new(uri) # => #<Gem::Net::HTTP::Mkcol MKCOL>
|
||||
# res = Gem::Net::HTTP.start(hostname) do |http|
|
||||
@ -335,7 +335,7 @@ end
|
||||
# {WebDAV method COPY}[http://www.webdav.org/specs/rfc4918.html#METHOD_COPY]:
|
||||
#
|
||||
# require 'rubygems/net-http/lib/net/http'
|
||||
# uri = URI('http://example.com')
|
||||
# uri = Gem::URI('http://example.com')
|
||||
# hostname = uri.hostname # => "example.com"
|
||||
# req = Gem::Net::HTTP::Copy.new(uri) # => #<Gem::Net::HTTP::Copy COPY>
|
||||
# res = Gem::Net::HTTP.start(hostname) do |http|
|
||||
@ -358,7 +358,7 @@ end
|
||||
# {WebDAV method MOVE}[http://www.webdav.org/specs/rfc4918.html#METHOD_MOVE]:
|
||||
#
|
||||
# require 'rubygems/net-http/lib/net/http'
|
||||
# uri = URI('http://example.com')
|
||||
# uri = Gem::URI('http://example.com')
|
||||
# hostname = uri.hostname # => "example.com"
|
||||
# req = Gem::Net::HTTP::Move.new(uri) # => #<Gem::Net::HTTP::Move MOVE>
|
||||
# res = Gem::Net::HTTP.start(hostname) do |http|
|
||||
@ -381,7 +381,7 @@ end
|
||||
# {WebDAV method LOCK}[http://www.webdav.org/specs/rfc4918.html#METHOD_LOCK]:
|
||||
#
|
||||
# require 'rubygems/net-http/lib/net/http'
|
||||
# uri = URI('http://example.com')
|
||||
# uri = Gem::URI('http://example.com')
|
||||
# hostname = uri.hostname # => "example.com"
|
||||
# req = Gem::Net::HTTP::Lock.new(uri) # => #<Gem::Net::HTTP::Lock LOCK>
|
||||
# res = Gem::Net::HTTP.start(hostname) do |http|
|
||||
@ -404,7 +404,7 @@ end
|
||||
# {WebDAV method UNLOCK}[http://www.webdav.org/specs/rfc4918.html#METHOD_UNLOCK]:
|
||||
#
|
||||
# require 'rubygems/net-http/lib/net/http'
|
||||
# uri = URI('http://example.com')
|
||||
# uri = Gem::URI('http://example.com')
|
||||
# hostname = uri.hostname # => "example.com"
|
||||
# req = Gem::Net::HTTP::Unlock.new(uri) # => #<Gem::Net::HTTP::Unlock UNLOCK>
|
||||
# res = Gem::Net::HTTP.start(hostname) do |http|
|
||||
|
@ -216,8 +216,8 @@ class Gem::Net::HTTPResponse
|
||||
attr_reader :message
|
||||
alias msg message # :nodoc: obsolete
|
||||
|
||||
# The URI used to fetch this response. The response URI is only available
|
||||
# if a URI was used to create the request.
|
||||
# The Gem::URI used to fetch this response. The response Gem::URI is only available
|
||||
# if a Gem::URI was used to create the request.
|
||||
attr_reader :uri
|
||||
|
||||
# Set to true automatically when the request did not contain an
|
||||
|
@ -379,7 +379,7 @@ module Gem::Net
|
||||
|
||||
# Response class for <tt>See Other</tt> responses (status code 303).
|
||||
#
|
||||
# The response to the request can be found under another URI using the GET method.
|
||||
# The response to the request can be found under another Gem::URI using the GET method.
|
||||
#
|
||||
# :include: doc/net-http/included_getters.rdoc
|
||||
#
|
||||
@ -428,8 +428,8 @@ module Gem::Net
|
||||
|
||||
# Response class for <tt>Temporary Redirect</tt> responses (status code 307).
|
||||
#
|
||||
# The request should be repeated with another URI;
|
||||
# however, future requests should still use the original URI.
|
||||
# The request should be repeated with another Gem::URI;
|
||||
# however, future requests should still use the original Gem::URI.
|
||||
#
|
||||
# :include: doc/net-http/included_getters.rdoc
|
||||
#
|
||||
@ -445,7 +445,7 @@ module Gem::Net
|
||||
|
||||
# Response class for <tt>Permanent Redirect</tt> responses (status code 308).
|
||||
#
|
||||
# This and all future requests should be directed to the given URI.
|
||||
# This and all future requests should be directed to the given Gem::URI.
|
||||
#
|
||||
# :include: doc/net-http/included_getters.rdoc
|
||||
#
|
||||
@ -690,9 +690,9 @@ module Gem::Net
|
||||
end
|
||||
HTTPRequestEntityTooLarge = HTTPPayloadTooLarge
|
||||
|
||||
# Response class for <tt>URI Too Long</tt> responses (status code 414).
|
||||
# Response class for <tt>Gem::URI Too Long</tt> responses (status code 414).
|
||||
#
|
||||
# The URI provided was too long for the server to process.
|
||||
# The Gem::URI provided was too long for the server to process.
|
||||
#
|
||||
# :include: doc/net-http/included_getters.rdoc
|
||||
#
|
||||
|
@ -11,7 +11,7 @@ if $0 == __FILE__
|
||||
puts
|
||||
puts "Gem::Net::HTTP::STATUS_CODES = {"
|
||||
url = "https://www.iana.org/assignments/http-status-codes/http-status-codes-1.csv"
|
||||
URI(url).read.each_line do |line|
|
||||
Gem::URI(url).read.each_line do |line|
|
||||
code, mes, = line.split(',')
|
||||
next if ['(Unused)', 'Unassigned', 'Description'].include?(mes)
|
||||
puts " #{code} => '#{mes}',"
|
||||
|
@ -158,7 +158,7 @@
|
||||
# - Date -- Anything accepted by +Date.parse+ (need to require +optparse/date+)
|
||||
# - DateTime -- Anything accepted by +DateTime.parse+ (need to require +optparse/date+)
|
||||
# - Time -- Anything accepted by +Time.httpdate+ or +Time.parse+ (need to require +optparse/time+)
|
||||
# - URI -- Anything accepted by +URI.parse+ (need to require +optparse/uri+)
|
||||
# - URI -- Anything accepted by +Gem::URI.parse+ (need to require +optparse/uri+)
|
||||
# - Shellwords -- Anything accepted by +Shellwords.shellwords+ (need to require +optparse/shellwords+)
|
||||
# - String -- Any non-empty string
|
||||
# - Integer -- Any integer. Will convert octal. (e.g. 124, -3, 040)
|
||||
|
@ -2,6 +2,6 @@
|
||||
# -*- ruby -*-
|
||||
|
||||
require_relative '../optparse'
|
||||
require 'uri'
|
||||
require_relative '../../../vendor/uri/lib/uri'
|
||||
|
||||
Gem::OptionParser.accept(URI) {|s,| URI.parse(s) if s}
|
||||
Gem::OptionParser.accept(Gem::URI) {|s,| Gem::URI.parse(s) if s}
|
||||
|
@ -76,7 +76,7 @@ class Gem::RemoteFetcher
|
||||
require_relative "core_ext/tcpsocket_init" if Gem.configuration.ipv4_fallback_enabled
|
||||
require_relative "net/http"
|
||||
require "stringio"
|
||||
require "uri"
|
||||
require_relative "vendor/uri/lib/uri"
|
||||
|
||||
Socket.do_not_reverse_lookup = true
|
||||
|
||||
@ -135,7 +135,7 @@ class Gem::RemoteFetcher
|
||||
|
||||
scheme = source_uri.scheme
|
||||
|
||||
# URI.parse gets confused by MS Windows paths with forward slashes.
|
||||
# Gem::URI.parse gets confused by MS Windows paths with forward slashes.
|
||||
scheme = nil if /^[a-z]$/i.match?(scheme)
|
||||
|
||||
# REFACTOR: split this up and dispatch on scheme (eg download_http)
|
||||
|
@ -18,11 +18,11 @@ class Gem::Request
|
||||
end
|
||||
|
||||
def self.proxy_uri(proxy) # :nodoc:
|
||||
require "uri"
|
||||
require_relative "vendor/uri/lib/uri"
|
||||
case proxy
|
||||
when :no_proxy then nil
|
||||
when URI::HTTP then proxy
|
||||
else URI.parse(proxy)
|
||||
when Gem::URI::HTTP then proxy
|
||||
else Gem::URI.parse(proxy)
|
||||
end
|
||||
end
|
||||
|
||||
@ -176,7 +176,7 @@ class Gem::Request
|
||||
end
|
||||
|
||||
require "uri"
|
||||
uri = URI(Gem::UriFormatter.new(env_proxy).normalize)
|
||||
uri = Gem::URI(Gem::UriFormatter.new(env_proxy).normalize)
|
||||
|
||||
if uri && uri.user.nil? && uri.password.nil?
|
||||
user = ENV["#{downcase_scheme}_proxy_user"] || ENV["#{upcase_scheme}_PROXY_USER"]
|
||||
|
@ -30,7 +30,7 @@ class Gem::Resolver::APISet < Gem::Resolver::Set
|
||||
def initialize(dep_uri = "https://index.rubygems.org/info/")
|
||||
super()
|
||||
|
||||
dep_uri = URI dep_uri unless URI === dep_uri
|
||||
dep_uri = Gem::URI dep_uri unless Gem::URI === dep_uri
|
||||
|
||||
@dep_uri = dep_uri
|
||||
@uri = dep_uri + ".."
|
||||
|
@ -60,7 +60,7 @@ class Gem::Resolver::BestSet < Gem::Resolver::ComposedSet
|
||||
|
||||
def replace_failed_api_set(error) # :nodoc:
|
||||
uri = error.original_uri
|
||||
uri = URI uri unless URI === uri
|
||||
uri = Gem::URI uri unless Gem::URI === uri
|
||||
uri += "."
|
||||
|
||||
raise error unless api_set = @sets.find do |set|
|
||||
|
@ -49,7 +49,7 @@ class Gem::S3URISigner
|
||||
string_to_sign = generate_string_to_sign(date_time, credential_info, canonical_request)
|
||||
signature = generate_signature(s3_config, date, string_to_sign)
|
||||
|
||||
URI.parse("https://#{canonical_host}#{uri.path}?#{query_params}&X-Amz-Signature=#{signature}")
|
||||
Gem::URI.parse("https://#{canonical_host}#{uri.path}?#{query_params}&X-Amz-Signature=#{signature}")
|
||||
end
|
||||
|
||||
private
|
||||
@ -152,7 +152,7 @@ class Gem::S3URISigner
|
||||
end
|
||||
|
||||
def ec2_metadata_request(url)
|
||||
uri = URI(url)
|
||||
uri = Gem::URI(url)
|
||||
@request_pool ||= create_request_pool(uri)
|
||||
request = Gem::Request.new(uri, Gem::Net::HTTP::Get, nil, @request_pool)
|
||||
response = request.fetch
|
||||
|
@ -221,14 +221,14 @@ class Gem::Source::Git < Gem::Source
|
||||
end
|
||||
|
||||
##
|
||||
# A hash for the git gem based on the git repository URI.
|
||||
# A hash for the git gem based on the git repository Gem::URI.
|
||||
|
||||
def uri_hash # :nodoc:
|
||||
require_relative "../openssl"
|
||||
|
||||
normalized =
|
||||
if @repository.match?(%r{^\w+://(\w+@)?})
|
||||
uri = URI(@repository).normalize.to_s.sub %r{/$},""
|
||||
uri = Gem::URI(@repository).normalize.to_s.sub %r{/$},""
|
||||
uri.sub(/\A(\w+)/) { $1.downcase }
|
||||
else
|
||||
@repository
|
||||
|
@ -44,7 +44,7 @@ class Gem::SourceList
|
||||
end
|
||||
|
||||
##
|
||||
# Appends +obj+ to the source list which may be a Gem::Source, URI or URI
|
||||
# Appends +obj+ to the source list which may be a Gem::Source, Gem::URI or URI
|
||||
# String.
|
||||
|
||||
def <<(obj)
|
||||
|
@ -427,13 +427,13 @@ or set it to nil if you don't want to specify a license.
|
||||
|
||||
# Make sure a homepage is valid HTTP/HTTPS URI
|
||||
if homepage && !homepage.empty?
|
||||
require "uri"
|
||||
require_relative "vendor/uri/lib/uri"
|
||||
begin
|
||||
homepage_uri = URI.parse(homepage)
|
||||
unless [URI::HTTP, URI::HTTPS].member? homepage_uri.class
|
||||
homepage_uri = Gem::URI.parse(homepage)
|
||||
unless [Gem::URI::HTTP, Gem::URI::HTTPS].member? homepage_uri.class
|
||||
error "\"#{homepage}\" is not a valid HTTP URI"
|
||||
end
|
||||
rescue URI::InvalidURIError
|
||||
rescue Gem::URI::InvalidURIError
|
||||
error "\"#{homepage}\" is not a valid HTTP URI"
|
||||
end
|
||||
end
|
||||
|
@ -16,9 +16,9 @@ class Gem::Uri
|
||||
# Parses uri, raising if it's invalid
|
||||
|
||||
def self.parse!(uri)
|
||||
require "uri"
|
||||
require_relative "vendor/uri/lib/uri"
|
||||
|
||||
raise URI::InvalidURIError unless uri
|
||||
raise Gem::URI::InvalidURIError unless uri
|
||||
|
||||
return uri unless uri.is_a?(String)
|
||||
|
||||
@ -28,9 +28,9 @@ class Gem::Uri
|
||||
# as "%7BDESede%7D". If this is escaped again the percentage
|
||||
# symbols will be escaped.
|
||||
begin
|
||||
URI.parse(uri)
|
||||
rescue URI::InvalidURIError
|
||||
URI.parse(URI::DEFAULT_PARSER.escape(uri))
|
||||
Gem::URI.parse(uri)
|
||||
rescue Gem::URI::InvalidURIError
|
||||
Gem::URI.parse(Gem::URI::DEFAULT_PARSER.escape(uri))
|
||||
end
|
||||
end
|
||||
|
||||
@ -39,7 +39,7 @@ class Gem::Uri
|
||||
|
||||
def self.parse(uri)
|
||||
parse!(uri)
|
||||
rescue URI::InvalidURIError
|
||||
rescue Gem::URI::InvalidURIError
|
||||
uri
|
||||
end
|
||||
|
||||
|
@ -105,7 +105,7 @@ module Gem::Util
|
||||
end
|
||||
|
||||
##
|
||||
# Corrects +path+ (usually returned by `URI.parse().path` on Windows), that
|
||||
# Corrects +path+ (usually returned by `Gem::URI.parse().path` on Windows), that
|
||||
# comes with a leading slash.
|
||||
|
||||
def self.correct_for_windows_path(path)
|
||||
|
1
lib/rubygems/vendor/uri/.document
vendored
Normal file
1
lib/rubygems/vendor/uri/.document
vendored
Normal file
@ -0,0 +1 @@
|
||||
# Vendored files do not need to be documented
|
22
lib/rubygems/vendor/uri/LICENSE.txt
vendored
Normal file
22
lib/rubygems/vendor/uri/LICENSE.txt
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
104
lib/rubygems/vendor/uri/lib/uri.rb
vendored
Normal file
104
lib/rubygems/vendor/uri/lib/uri.rb
vendored
Normal file
@ -0,0 +1,104 @@
|
||||
# frozen_string_literal: false
|
||||
# Gem::URI is a module providing classes to handle Uniform Resource Identifiers
|
||||
# (RFC2396[http://tools.ietf.org/html/rfc2396]).
|
||||
#
|
||||
# == Features
|
||||
#
|
||||
# * Uniform way of handling URIs.
|
||||
# * Flexibility to introduce custom Gem::URI schemes.
|
||||
# * Flexibility to have an alternate Gem::URI::Parser (or just different patterns
|
||||
# and regexp's).
|
||||
#
|
||||
# == Basic example
|
||||
#
|
||||
# require 'rubygems/vendor/uri/lib/uri'
|
||||
#
|
||||
# uri = Gem::URI("http://foo.com/posts?id=30&limit=5#time=1305298413")
|
||||
# #=> #<Gem::URI::HTTP http://foo.com/posts?id=30&limit=5#time=1305298413>
|
||||
#
|
||||
# uri.scheme #=> "http"
|
||||
# uri.host #=> "foo.com"
|
||||
# uri.path #=> "/posts"
|
||||
# uri.query #=> "id=30&limit=5"
|
||||
# uri.fragment #=> "time=1305298413"
|
||||
#
|
||||
# uri.to_s #=> "http://foo.com/posts?id=30&limit=5#time=1305298413"
|
||||
#
|
||||
# == Adding custom URIs
|
||||
#
|
||||
# module Gem::URI
|
||||
# class RSYNC < Generic
|
||||
# DEFAULT_PORT = 873
|
||||
# end
|
||||
# register_scheme 'RSYNC', RSYNC
|
||||
# end
|
||||
# #=> Gem::URI::RSYNC
|
||||
#
|
||||
# Gem::URI.scheme_list
|
||||
# #=> {"FILE"=>Gem::URI::File, "FTP"=>Gem::URI::FTP, "HTTP"=>Gem::URI::HTTP,
|
||||
# # "HTTPS"=>Gem::URI::HTTPS, "LDAP"=>Gem::URI::LDAP, "LDAPS"=>Gem::URI::LDAPS,
|
||||
# # "MAILTO"=>Gem::URI::MailTo, "RSYNC"=>Gem::URI::RSYNC}
|
||||
#
|
||||
# uri = Gem::URI("rsync://rsync.foo.com")
|
||||
# #=> #<Gem::URI::RSYNC rsync://rsync.foo.com>
|
||||
#
|
||||
# == RFC References
|
||||
#
|
||||
# A good place to view an RFC spec is http://www.ietf.org/rfc.html.
|
||||
#
|
||||
# Here is a list of all related RFC's:
|
||||
# - RFC822[http://tools.ietf.org/html/rfc822]
|
||||
# - RFC1738[http://tools.ietf.org/html/rfc1738]
|
||||
# - RFC2255[http://tools.ietf.org/html/rfc2255]
|
||||
# - RFC2368[http://tools.ietf.org/html/rfc2368]
|
||||
# - RFC2373[http://tools.ietf.org/html/rfc2373]
|
||||
# - RFC2396[http://tools.ietf.org/html/rfc2396]
|
||||
# - RFC2732[http://tools.ietf.org/html/rfc2732]
|
||||
# - RFC3986[http://tools.ietf.org/html/rfc3986]
|
||||
#
|
||||
# == Class tree
|
||||
#
|
||||
# - Gem::URI::Generic (in uri/generic.rb)
|
||||
# - Gem::URI::File - (in uri/file.rb)
|
||||
# - Gem::URI::FTP - (in uri/ftp.rb)
|
||||
# - Gem::URI::HTTP - (in uri/http.rb)
|
||||
# - Gem::URI::HTTPS - (in uri/https.rb)
|
||||
# - Gem::URI::LDAP - (in uri/ldap.rb)
|
||||
# - Gem::URI::LDAPS - (in uri/ldaps.rb)
|
||||
# - Gem::URI::MailTo - (in uri/mailto.rb)
|
||||
# - Gem::URI::Parser - (in uri/common.rb)
|
||||
# - Gem::URI::REGEXP - (in uri/common.rb)
|
||||
# - Gem::URI::REGEXP::PATTERN - (in uri/common.rb)
|
||||
# - Gem::URI::Util - (in uri/common.rb)
|
||||
# - Gem::URI::Error - (in uri/common.rb)
|
||||
# - Gem::URI::InvalidURIError - (in uri/common.rb)
|
||||
# - Gem::URI::InvalidComponentError - (in uri/common.rb)
|
||||
# - Gem::URI::BadURIError - (in uri/common.rb)
|
||||
#
|
||||
# == Copyright Info
|
||||
#
|
||||
# Author:: Akira Yamada <akira@ruby-lang.org>
|
||||
# Documentation::
|
||||
# Akira Yamada <akira@ruby-lang.org>
|
||||
# Dmitry V. Sabanin <sdmitry@lrn.ru>
|
||||
# Vincent Batts <vbatts@hashbangbash.com>
|
||||
# License::
|
||||
# Copyright (c) 2001 akira yamada <akira@ruby-lang.org>
|
||||
# You can redistribute it and/or modify it under the same term as Ruby.
|
||||
#
|
||||
|
||||
module Gem::URI
|
||||
end
|
||||
|
||||
require_relative 'uri/version'
|
||||
require_relative 'uri/common'
|
||||
require_relative 'uri/generic'
|
||||
require_relative 'uri/file'
|
||||
require_relative 'uri/ftp'
|
||||
require_relative 'uri/http'
|
||||
require_relative 'uri/https'
|
||||
require_relative 'uri/ldap'
|
||||
require_relative 'uri/ldaps'
|
||||
require_relative 'uri/mailto'
|
||||
require_relative 'uri/ws'
|
||||
require_relative 'uri/wss'
|
853
lib/rubygems/vendor/uri/lib/uri/common.rb
vendored
Normal file
853
lib/rubygems/vendor/uri/lib/uri/common.rb
vendored
Normal file
@ -0,0 +1,853 @@
|
||||
# frozen_string_literal: true
|
||||
#--
|
||||
# = uri/common.rb
|
||||
#
|
||||
# Author:: Akira Yamada <akira@ruby-lang.org>
|
||||
# License::
|
||||
# You can redistribute it and/or modify it under the same term as Ruby.
|
||||
#
|
||||
# See Gem::URI for general documentation
|
||||
#
|
||||
|
||||
require_relative "rfc2396_parser"
|
||||
require_relative "rfc3986_parser"
|
||||
|
||||
module Gem::URI
|
||||
include RFC2396_REGEXP
|
||||
|
||||
REGEXP = RFC2396_REGEXP
|
||||
Parser = RFC2396_Parser
|
||||
RFC3986_PARSER = RFC3986_Parser.new
|
||||
Ractor.make_shareable(RFC3986_PARSER) if defined?(Ractor)
|
||||
|
||||
# Gem::URI::Parser.new
|
||||
DEFAULT_PARSER = Parser.new
|
||||
DEFAULT_PARSER.pattern.each_pair do |sym, str|
|
||||
unless REGEXP::PATTERN.const_defined?(sym)
|
||||
REGEXP::PATTERN.const_set(sym, str)
|
||||
end
|
||||
end
|
||||
DEFAULT_PARSER.regexp.each_pair do |sym, str|
|
||||
const_set(sym, str)
|
||||
end
|
||||
Ractor.make_shareable(DEFAULT_PARSER) if defined?(Ractor)
|
||||
|
||||
module Util # :nodoc:
|
||||
def make_components_hash(klass, array_hash)
|
||||
tmp = {}
|
||||
if array_hash.kind_of?(Array) &&
|
||||
array_hash.size == klass.component.size - 1
|
||||
klass.component[1..-1].each_index do |i|
|
||||
begin
|
||||
tmp[klass.component[i + 1]] = array_hash[i].clone
|
||||
rescue TypeError
|
||||
tmp[klass.component[i + 1]] = array_hash[i]
|
||||
end
|
||||
end
|
||||
|
||||
elsif array_hash.kind_of?(Hash)
|
||||
array_hash.each do |key, value|
|
||||
begin
|
||||
tmp[key] = value.clone
|
||||
rescue TypeError
|
||||
tmp[key] = value
|
||||
end
|
||||
end
|
||||
else
|
||||
raise ArgumentError,
|
||||
"expected Array of or Hash of components of #{klass} (#{klass.component[1..-1].join(', ')})"
|
||||
end
|
||||
tmp[:scheme] = klass.to_s.sub(/\A.*::/, '').downcase
|
||||
|
||||
return tmp
|
||||
end
|
||||
module_function :make_components_hash
|
||||
end
|
||||
|
||||
module Schemes
|
||||
end
|
||||
private_constant :Schemes
|
||||
|
||||
# Registers the given +klass+ as the class to be instantiated
|
||||
# when parsing a \Gem::URI with the given +scheme+:
|
||||
#
|
||||
# Gem::URI.register_scheme('MS_SEARCH', Gem::URI::Generic) # => Gem::URI::Generic
|
||||
# Gem::URI.scheme_list['MS_SEARCH'] # => Gem::URI::Generic
|
||||
#
|
||||
# Note that after calling String#upcase on +scheme+, it must be a valid
|
||||
# constant name.
|
||||
def self.register_scheme(scheme, klass)
|
||||
Schemes.const_set(scheme.to_s.upcase, klass)
|
||||
end
|
||||
|
||||
# Returns a hash of the defined schemes:
|
||||
#
|
||||
# Gem::URI.scheme_list
|
||||
# # =>
|
||||
# {"MAILTO"=>Gem::URI::MailTo,
|
||||
# "LDAPS"=>Gem::URI::LDAPS,
|
||||
# "WS"=>Gem::URI::WS,
|
||||
# "HTTP"=>Gem::URI::HTTP,
|
||||
# "HTTPS"=>Gem::URI::HTTPS,
|
||||
# "LDAP"=>Gem::URI::LDAP,
|
||||
# "FILE"=>Gem::URI::File,
|
||||
# "FTP"=>Gem::URI::FTP}
|
||||
#
|
||||
# Related: Gem::URI.register_scheme.
|
||||
def self.scheme_list
|
||||
Schemes.constants.map { |name|
|
||||
[name.to_s.upcase, Schemes.const_get(name)]
|
||||
}.to_h
|
||||
end
|
||||
|
||||
INITIAL_SCHEMES = scheme_list
|
||||
private_constant :INITIAL_SCHEMES
|
||||
Ractor.make_shareable(INITIAL_SCHEMES) if defined?(Ractor)
|
||||
|
||||
# Returns a new object constructed from the given +scheme+, +arguments+,
|
||||
# and +default+:
|
||||
#
|
||||
# - The new object is an instance of <tt>Gem::URI.scheme_list[scheme.upcase]</tt>.
|
||||
# - The object is initialized by calling the class initializer
|
||||
# using +scheme+ and +arguments+.
|
||||
# See Gem::URI::Generic.new.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# values = ['john.doe', 'www.example.com', '123', nil, '/forum/questions/', nil, 'tag=networking&order=newest', 'top']
|
||||
# Gem::URI.for('https', *values)
|
||||
# # => #<Gem::URI::HTTPS https://john.doe@www.example.com:123/forum/questions/?tag=networking&order=newest#top>
|
||||
# Gem::URI.for('foo', *values, default: Gem::URI::HTTP)
|
||||
# # => #<Gem::URI::HTTP foo://john.doe@www.example.com:123/forum/questions/?tag=networking&order=newest#top>
|
||||
#
|
||||
def self.for(scheme, *arguments, default: Generic)
|
||||
const_name = scheme.to_s.upcase
|
||||
|
||||
uri_class = INITIAL_SCHEMES[const_name]
|
||||
uri_class ||= if /\A[A-Z]\w*\z/.match?(const_name) && Schemes.const_defined?(const_name, false)
|
||||
Schemes.const_get(const_name, false)
|
||||
end
|
||||
uri_class ||= default
|
||||
|
||||
return uri_class.new(scheme, *arguments)
|
||||
end
|
||||
|
||||
#
|
||||
# Base class for all Gem::URI exceptions.
|
||||
#
|
||||
class Error < StandardError; end
|
||||
#
|
||||
# Not a Gem::URI.
|
||||
#
|
||||
class InvalidURIError < Error; end
|
||||
#
|
||||
# Not a Gem::URI component.
|
||||
#
|
||||
class InvalidComponentError < Error; end
|
||||
#
|
||||
# Gem::URI is valid, bad usage is not.
|
||||
#
|
||||
class BadURIError < Error; end
|
||||
|
||||
# Returns a 9-element array representing the parts of the \Gem::URI
|
||||
# formed from the string +uri+;
|
||||
# each array element is a string or +nil+:
|
||||
#
|
||||
# names = %w[scheme userinfo host port registry path opaque query fragment]
|
||||
# values = Gem::URI.split('https://john.doe@www.example.com:123/forum/questions/?tag=networking&order=newest#top')
|
||||
# names.zip(values)
|
||||
# # =>
|
||||
# [["scheme", "https"],
|
||||
# ["userinfo", "john.doe"],
|
||||
# ["host", "www.example.com"],
|
||||
# ["port", "123"],
|
||||
# ["registry", nil],
|
||||
# ["path", "/forum/questions/"],
|
||||
# ["opaque", nil],
|
||||
# ["query", "tag=networking&order=newest"],
|
||||
# ["fragment", "top"]]
|
||||
#
|
||||
def self.split(uri)
|
||||
RFC3986_PARSER.split(uri)
|
||||
end
|
||||
|
||||
# Returns a new \Gem::URI object constructed from the given string +uri+:
|
||||
#
|
||||
# Gem::URI.parse('https://john.doe@www.example.com:123/forum/questions/?tag=networking&order=newest#top')
|
||||
# # => #<Gem::URI::HTTPS https://john.doe@www.example.com:123/forum/questions/?tag=networking&order=newest#top>
|
||||
# Gem::URI.parse('http://john.doe@www.example.com:123/forum/questions/?tag=networking&order=newest#top')
|
||||
# # => #<Gem::URI::HTTP http://john.doe@www.example.com:123/forum/questions/?tag=networking&order=newest#top>
|
||||
#
|
||||
# It's recommended to first ::escape string +uri+
|
||||
# if it may contain invalid Gem::URI characters.
|
||||
#
|
||||
def self.parse(uri)
|
||||
RFC3986_PARSER.parse(uri)
|
||||
end
|
||||
|
||||
# Merges the given Gem::URI strings +str+
|
||||
# per {RFC 2396}[https://www.rfc-editor.org/rfc/rfc2396.html].
|
||||
#
|
||||
# Each string in +str+ is converted to an
|
||||
# {RFC3986 Gem::URI}[https://www.rfc-editor.org/rfc/rfc3986.html] before being merged.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# Gem::URI.join("http://example.com/","main.rbx")
|
||||
# # => #<Gem::URI::HTTP http://example.com/main.rbx>
|
||||
#
|
||||
# Gem::URI.join('http://example.com', 'foo')
|
||||
# # => #<Gem::URI::HTTP http://example.com/foo>
|
||||
#
|
||||
# Gem::URI.join('http://example.com', '/foo', '/bar')
|
||||
# # => #<Gem::URI::HTTP http://example.com/bar>
|
||||
#
|
||||
# Gem::URI.join('http://example.com', '/foo', 'bar')
|
||||
# # => #<Gem::URI::HTTP http://example.com/bar>
|
||||
#
|
||||
# Gem::URI.join('http://example.com', '/foo/', 'bar')
|
||||
# # => #<Gem::URI::HTTP http://example.com/foo/bar>
|
||||
#
|
||||
def self.join(*str)
|
||||
RFC3986_PARSER.join(*str)
|
||||
end
|
||||
|
||||
#
|
||||
# == Synopsis
|
||||
#
|
||||
# Gem::URI::extract(str[, schemes][,&blk])
|
||||
#
|
||||
# == Args
|
||||
#
|
||||
# +str+::
|
||||
# String to extract URIs from.
|
||||
# +schemes+::
|
||||
# Limit Gem::URI matching to specific schemes.
|
||||
#
|
||||
# == Description
|
||||
#
|
||||
# Extracts URIs from a string. If block given, iterates through all matched URIs.
|
||||
# Returns nil if block given or array with matches.
|
||||
#
|
||||
# == Usage
|
||||
#
|
||||
# require "rubygems/vendor/uri/lib/uri"
|
||||
#
|
||||
# Gem::URI.extract("text here http://foo.example.org/bla and here mailto:test@example.com and here also.")
|
||||
# # => ["http://foo.example.com/bla", "mailto:test@example.com"]
|
||||
#
|
||||
def self.extract(str, schemes = nil, &block) # :nodoc:
|
||||
warn "Gem::URI.extract is obsolete", uplevel: 1 if $VERBOSE
|
||||
DEFAULT_PARSER.extract(str, schemes, &block)
|
||||
end
|
||||
|
||||
#
|
||||
# == Synopsis
|
||||
#
|
||||
# Gem::URI::regexp([match_schemes])
|
||||
#
|
||||
# == Args
|
||||
#
|
||||
# +match_schemes+::
|
||||
# Array of schemes. If given, resulting regexp matches to URIs
|
||||
# whose scheme is one of the match_schemes.
|
||||
#
|
||||
# == Description
|
||||
#
|
||||
# Returns a Regexp object which matches to Gem::URI-like strings.
|
||||
# The Regexp object returned by this method includes arbitrary
|
||||
# number of capture group (parentheses). Never rely on its number.
|
||||
#
|
||||
# == Usage
|
||||
#
|
||||
# require 'rubygems/vendor/uri/lib/uri'
|
||||
#
|
||||
# # extract first Gem::URI from html_string
|
||||
# html_string.slice(Gem::URI.regexp)
|
||||
#
|
||||
# # remove ftp URIs
|
||||
# html_string.sub(Gem::URI.regexp(['ftp']), '')
|
||||
#
|
||||
# # You should not rely on the number of parentheses
|
||||
# html_string.scan(Gem::URI.regexp) do |*matches|
|
||||
# p $&
|
||||
# end
|
||||
#
|
||||
def self.regexp(schemes = nil)# :nodoc:
|
||||
warn "Gem::URI.regexp is obsolete", uplevel: 1 if $VERBOSE
|
||||
DEFAULT_PARSER.make_regexp(schemes)
|
||||
end
|
||||
|
||||
TBLENCWWWCOMP_ = {} # :nodoc:
|
||||
256.times do |i|
|
||||
TBLENCWWWCOMP_[-i.chr] = -('%%%02X' % i)
|
||||
end
|
||||
TBLENCURICOMP_ = TBLENCWWWCOMP_.dup.freeze
|
||||
TBLENCWWWCOMP_[' '] = '+'
|
||||
TBLENCWWWCOMP_.freeze
|
||||
TBLDECWWWCOMP_ = {} # :nodoc:
|
||||
256.times do |i|
|
||||
h, l = i>>4, i&15
|
||||
TBLDECWWWCOMP_[-('%%%X%X' % [h, l])] = -i.chr
|
||||
TBLDECWWWCOMP_[-('%%%x%X' % [h, l])] = -i.chr
|
||||
TBLDECWWWCOMP_[-('%%%X%x' % [h, l])] = -i.chr
|
||||
TBLDECWWWCOMP_[-('%%%x%x' % [h, l])] = -i.chr
|
||||
end
|
||||
TBLDECWWWCOMP_['+'] = ' '
|
||||
TBLDECWWWCOMP_.freeze
|
||||
|
||||
# Returns a URL-encoded string derived from the given string +str+.
|
||||
#
|
||||
# The returned string:
|
||||
#
|
||||
# - Preserves:
|
||||
#
|
||||
# - Characters <tt>'*'</tt>, <tt>'.'</tt>, <tt>'-'</tt>, and <tt>'_'</tt>.
|
||||
# - Character in ranges <tt>'a'..'z'</tt>, <tt>'A'..'Z'</tt>,
|
||||
# and <tt>'0'..'9'</tt>.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# Gem::URI.encode_www_form_component('*.-_azAZ09')
|
||||
# # => "*.-_azAZ09"
|
||||
#
|
||||
# - Converts:
|
||||
#
|
||||
# - Character <tt>' '</tt> to character <tt>'+'</tt>.
|
||||
# - Any other character to "percent notation";
|
||||
# the percent notation for character <i>c</i> is <tt>'%%%X' % c.ord</tt>.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# Gem::URI.encode_www_form_component('Here are some punctuation characters: ,;?:')
|
||||
# # => "Here+are+some+punctuation+characters%3A+%2C%3B%3F%3A"
|
||||
#
|
||||
# Encoding:
|
||||
#
|
||||
# - If +str+ has encoding Encoding::ASCII_8BIT, argument +enc+ is ignored.
|
||||
# - Otherwise +str+ is converted first to Encoding::UTF_8
|
||||
# (with suitable character replacements),
|
||||
# and then to encoding +enc+.
|
||||
#
|
||||
# In either case, the returned string has forced encoding Encoding::US_ASCII.
|
||||
#
|
||||
# Related: Gem::URI.encode_uri_component (encodes <tt>' '</tt> as <tt>'%20'</tt>).
|
||||
def self.encode_www_form_component(str, enc=nil)
|
||||
_encode_uri_component(/[^*\-.0-9A-Z_a-z]/, TBLENCWWWCOMP_, str, enc)
|
||||
end
|
||||
|
||||
# Returns a string decoded from the given \URL-encoded string +str+.
|
||||
#
|
||||
# The given string is first encoded as Encoding::ASCII-8BIT (using String#b),
|
||||
# then decoded (as below), and finally force-encoded to the given encoding +enc+.
|
||||
#
|
||||
# The returned string:
|
||||
#
|
||||
# - Preserves:
|
||||
#
|
||||
# - Characters <tt>'*'</tt>, <tt>'.'</tt>, <tt>'-'</tt>, and <tt>'_'</tt>.
|
||||
# - Character in ranges <tt>'a'..'z'</tt>, <tt>'A'..'Z'</tt>,
|
||||
# and <tt>'0'..'9'</tt>.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# Gem::URI.decode_www_form_component('*.-_azAZ09')
|
||||
# # => "*.-_azAZ09"
|
||||
#
|
||||
# - Converts:
|
||||
#
|
||||
# - Character <tt>'+'</tt> to character <tt>' '</tt>.
|
||||
# - Each "percent notation" to an ASCII character.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# Gem::URI.decode_www_form_component('Here+are+some+punctuation+characters%3A+%2C%3B%3F%3A')
|
||||
# # => "Here are some punctuation characters: ,;?:"
|
||||
#
|
||||
# Related: Gem::URI.decode_uri_component (preserves <tt>'+'</tt>).
|
||||
def self.decode_www_form_component(str, enc=Encoding::UTF_8)
|
||||
_decode_uri_component(/\+|%\h\h/, str, enc)
|
||||
end
|
||||
|
||||
# Like Gem::URI.encode_www_form_component, except that <tt>' '</tt> (space)
|
||||
# is encoded as <tt>'%20'</tt> (instead of <tt>'+'</tt>).
|
||||
def self.encode_uri_component(str, enc=nil)
|
||||
_encode_uri_component(/[^*\-.0-9A-Z_a-z]/, TBLENCURICOMP_, str, enc)
|
||||
end
|
||||
|
||||
# Like Gem::URI.decode_www_form_component, except that <tt>'+'</tt> is preserved.
|
||||
def self.decode_uri_component(str, enc=Encoding::UTF_8)
|
||||
_decode_uri_component(/%\h\h/, str, enc)
|
||||
end
|
||||
|
||||
def self._encode_uri_component(regexp, table, str, enc)
|
||||
str = str.to_s.dup
|
||||
if str.encoding != Encoding::ASCII_8BIT
|
||||
if enc && enc != Encoding::ASCII_8BIT
|
||||
str.encode!(Encoding::UTF_8, invalid: :replace, undef: :replace)
|
||||
str.encode!(enc, fallback: ->(x){"&##{x.ord};"})
|
||||
end
|
||||
str.force_encoding(Encoding::ASCII_8BIT)
|
||||
end
|
||||
str.gsub!(regexp, table)
|
||||
str.force_encoding(Encoding::US_ASCII)
|
||||
end
|
||||
private_class_method :_encode_uri_component
|
||||
|
||||
def self._decode_uri_component(regexp, str, enc)
|
||||
raise ArgumentError, "invalid %-encoding (#{str})" if /%(?!\h\h)/.match?(str)
|
||||
str.b.gsub(regexp, TBLDECWWWCOMP_).force_encoding(enc)
|
||||
end
|
||||
private_class_method :_decode_uri_component
|
||||
|
||||
# Returns a URL-encoded string derived from the given
|
||||
# {Enumerable}[https://docs.ruby-lang.org/en/master/Enumerable.html#module-Enumerable-label-Enumerable+in+Ruby+Classes]
|
||||
# +enum+.
|
||||
#
|
||||
# The result is suitable for use as form data
|
||||
# for an \HTTP request whose <tt>Content-Type</tt> is
|
||||
# <tt>'application/x-www-form-urlencoded'</tt>.
|
||||
#
|
||||
# The returned string consists of the elements of +enum+,
|
||||
# each converted to one or more URL-encoded strings,
|
||||
# and all joined with character <tt>'&'</tt>.
|
||||
#
|
||||
# Simple examples:
|
||||
#
|
||||
# Gem::URI.encode_www_form([['foo', 0], ['bar', 1], ['baz', 2]])
|
||||
# # => "foo=0&bar=1&baz=2"
|
||||
# Gem::URI.encode_www_form({foo: 0, bar: 1, baz: 2})
|
||||
# # => "foo=0&bar=1&baz=2"
|
||||
#
|
||||
# The returned string is formed using method Gem::URI.encode_www_form_component,
|
||||
# which converts certain characters:
|
||||
#
|
||||
# Gem::URI.encode_www_form('f#o': '/', 'b-r': '$', 'b z': '@')
|
||||
# # => "f%23o=%2F&b-r=%24&b+z=%40"
|
||||
#
|
||||
# When +enum+ is Array-like, each element +ele+ is converted to a field:
|
||||
#
|
||||
# - If +ele+ is an array of two or more elements,
|
||||
# the field is formed from its first two elements
|
||||
# (and any additional elements are ignored):
|
||||
#
|
||||
# name = Gem::URI.encode_www_form_component(ele[0], enc)
|
||||
# value = Gem::URI.encode_www_form_component(ele[1], enc)
|
||||
# "#{name}=#{value}"
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# Gem::URI.encode_www_form([%w[foo bar], %w[baz bat bah]])
|
||||
# # => "foo=bar&baz=bat"
|
||||
# Gem::URI.encode_www_form([['foo', 0], ['bar', :baz, 'bat']])
|
||||
# # => "foo=0&bar=baz"
|
||||
#
|
||||
# - If +ele+ is an array of one element,
|
||||
# the field is formed from <tt>ele[0]</tt>:
|
||||
#
|
||||
# Gem::URI.encode_www_form_component(ele[0])
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# Gem::URI.encode_www_form([['foo'], [:bar], [0]])
|
||||
# # => "foo&bar&0"
|
||||
#
|
||||
# - Otherwise the field is formed from +ele+:
|
||||
#
|
||||
# Gem::URI.encode_www_form_component(ele)
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# Gem::URI.encode_www_form(['foo', :bar, 0])
|
||||
# # => "foo&bar&0"
|
||||
#
|
||||
# The elements of an Array-like +enum+ may be mixture:
|
||||
#
|
||||
# Gem::URI.encode_www_form([['foo', 0], ['bar', 1, 2], ['baz'], :bat])
|
||||
# # => "foo=0&bar=1&baz&bat"
|
||||
#
|
||||
# When +enum+ is Hash-like,
|
||||
# each +key+/+value+ pair is converted to one or more fields:
|
||||
#
|
||||
# - If +value+ is
|
||||
# {Array-convertible}[https://docs.ruby-lang.org/en/master/implicit_conversion_rdoc.html#label-Array-Convertible+Objects],
|
||||
# each element +ele+ in +value+ is paired with +key+ to form a field:
|
||||
#
|
||||
# name = Gem::URI.encode_www_form_component(key, enc)
|
||||
# value = Gem::URI.encode_www_form_component(ele, enc)
|
||||
# "#{name}=#{value}"
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# Gem::URI.encode_www_form({foo: [:bar, 1], baz: [:bat, :bam, 2]})
|
||||
# # => "foo=bar&foo=1&baz=bat&baz=bam&baz=2"
|
||||
#
|
||||
# - Otherwise, +key+ and +value+ are paired to form a field:
|
||||
#
|
||||
# name = Gem::URI.encode_www_form_component(key, enc)
|
||||
# value = Gem::URI.encode_www_form_component(value, enc)
|
||||
# "#{name}=#{value}"
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# Gem::URI.encode_www_form({foo: 0, bar: 1, baz: 2})
|
||||
# # => "foo=0&bar=1&baz=2"
|
||||
#
|
||||
# The elements of a Hash-like +enum+ may be mixture:
|
||||
#
|
||||
# Gem::URI.encode_www_form({foo: [0, 1], bar: 2})
|
||||
# # => "foo=0&foo=1&bar=2"
|
||||
#
|
||||
def self.encode_www_form(enum, enc=nil)
|
||||
enum.map do |k,v|
|
||||
if v.nil?
|
||||
encode_www_form_component(k, enc)
|
||||
elsif v.respond_to?(:to_ary)
|
||||
v.to_ary.map do |w|
|
||||
str = encode_www_form_component(k, enc)
|
||||
unless w.nil?
|
||||
str << '='
|
||||
str << encode_www_form_component(w, enc)
|
||||
end
|
||||
end.join('&')
|
||||
else
|
||||
str = encode_www_form_component(k, enc)
|
||||
str << '='
|
||||
str << encode_www_form_component(v, enc)
|
||||
end
|
||||
end.join('&')
|
||||
end
|
||||
|
||||
# Returns name/value pairs derived from the given string +str+,
|
||||
# which must be an ASCII string.
|
||||
#
|
||||
# The method may be used to decode the body of Net::HTTPResponse object +res+
|
||||
# for which <tt>res['Content-Type']</tt> is <tt>'application/x-www-form-urlencoded'</tt>.
|
||||
#
|
||||
# The returned data is an array of 2-element subarrays;
|
||||
# each subarray is a name/value pair (both are strings).
|
||||
# Each returned string has encoding +enc+,
|
||||
# and has had invalid characters removed via
|
||||
# {String#scrub}[https://docs.ruby-lang.org/en/master/String.html#method-i-scrub].
|
||||
#
|
||||
# A simple example:
|
||||
#
|
||||
# Gem::URI.decode_www_form('foo=0&bar=1&baz')
|
||||
# # => [["foo", "0"], ["bar", "1"], ["baz", ""]]
|
||||
#
|
||||
# The returned strings have certain conversions,
|
||||
# similar to those performed in Gem::URI.decode_www_form_component:
|
||||
#
|
||||
# Gem::URI.decode_www_form('f%23o=%2F&b-r=%24&b+z=%40')
|
||||
# # => [["f#o", "/"], ["b-r", "$"], ["b z", "@"]]
|
||||
#
|
||||
# The given string may contain consecutive separators:
|
||||
#
|
||||
# Gem::URI.decode_www_form('foo=0&&bar=1&&baz=2')
|
||||
# # => [["foo", "0"], ["", ""], ["bar", "1"], ["", ""], ["baz", "2"]]
|
||||
#
|
||||
# A different separator may be specified:
|
||||
#
|
||||
# Gem::URI.decode_www_form('foo=0--bar=1--baz', separator: '--')
|
||||
# # => [["foo", "0"], ["bar", "1"], ["baz", ""]]
|
||||
#
|
||||
def self.decode_www_form(str, enc=Encoding::UTF_8, separator: '&', use__charset_: false, isindex: false)
|
||||
raise ArgumentError, "the input of #{self.name}.#{__method__} must be ASCII only string" unless str.ascii_only?
|
||||
ary = []
|
||||
return ary if str.empty?
|
||||
enc = Encoding.find(enc)
|
||||
str.b.each_line(separator) do |string|
|
||||
string.chomp!(separator)
|
||||
key, sep, val = string.partition('=')
|
||||
if isindex
|
||||
if sep.empty?
|
||||
val = key
|
||||
key = +''
|
||||
end
|
||||
isindex = false
|
||||
end
|
||||
|
||||
if use__charset_ and key == '_charset_' and e = get_encoding(val)
|
||||
enc = e
|
||||
use__charset_ = false
|
||||
end
|
||||
|
||||
key.gsub!(/\+|%\h\h/, TBLDECWWWCOMP_)
|
||||
if val
|
||||
val.gsub!(/\+|%\h\h/, TBLDECWWWCOMP_)
|
||||
else
|
||||
val = +''
|
||||
end
|
||||
|
||||
ary << [key, val]
|
||||
end
|
||||
ary.each do |k, v|
|
||||
k.force_encoding(enc)
|
||||
k.scrub!
|
||||
v.force_encoding(enc)
|
||||
v.scrub!
|
||||
end
|
||||
ary
|
||||
end
|
||||
|
||||
private
|
||||
=begin command for WEB_ENCODINGS_
|
||||
curl https://encoding.spec.whatwg.org/encodings.json|
|
||||
ruby -rjson -e 'H={}
|
||||
h={
|
||||
"shift_jis"=>"Windows-31J",
|
||||
"euc-jp"=>"cp51932",
|
||||
"iso-2022-jp"=>"cp50221",
|
||||
"x-mac-cyrillic"=>"macCyrillic",
|
||||
}
|
||||
JSON($<.read).map{|x|x["encodings"]}.flatten.each{|x|
|
||||
Encoding.find(n=h.fetch(n=x["name"].downcase,n))rescue next
|
||||
x["labels"].each{|y|H[y]=n}
|
||||
}
|
||||
puts "{"
|
||||
H.each{|k,v|puts %[ #{k.dump}=>#{v.dump},]}
|
||||
puts "}"
|
||||
'
|
||||
=end
|
||||
WEB_ENCODINGS_ = {
|
||||
"unicode-1-1-utf-8"=>"utf-8",
|
||||
"utf-8"=>"utf-8",
|
||||
"utf8"=>"utf-8",
|
||||
"866"=>"ibm866",
|
||||
"cp866"=>"ibm866",
|
||||
"csibm866"=>"ibm866",
|
||||
"ibm866"=>"ibm866",
|
||||
"csisolatin2"=>"iso-8859-2",
|
||||
"iso-8859-2"=>"iso-8859-2",
|
||||
"iso-ir-101"=>"iso-8859-2",
|
||||
"iso8859-2"=>"iso-8859-2",
|
||||
"iso88592"=>"iso-8859-2",
|
||||
"iso_8859-2"=>"iso-8859-2",
|
||||
"iso_8859-2:1987"=>"iso-8859-2",
|
||||
"l2"=>"iso-8859-2",
|
||||
"latin2"=>"iso-8859-2",
|
||||
"csisolatin3"=>"iso-8859-3",
|
||||
"iso-8859-3"=>"iso-8859-3",
|
||||
"iso-ir-109"=>"iso-8859-3",
|
||||
"iso8859-3"=>"iso-8859-3",
|
||||
"iso88593"=>"iso-8859-3",
|
||||
"iso_8859-3"=>"iso-8859-3",
|
||||
"iso_8859-3:1988"=>"iso-8859-3",
|
||||
"l3"=>"iso-8859-3",
|
||||
"latin3"=>"iso-8859-3",
|
||||
"csisolatin4"=>"iso-8859-4",
|
||||
"iso-8859-4"=>"iso-8859-4",
|
||||
"iso-ir-110"=>"iso-8859-4",
|
||||
"iso8859-4"=>"iso-8859-4",
|
||||
"iso88594"=>"iso-8859-4",
|
||||
"iso_8859-4"=>"iso-8859-4",
|
||||
"iso_8859-4:1988"=>"iso-8859-4",
|
||||
"l4"=>"iso-8859-4",
|
||||
"latin4"=>"iso-8859-4",
|
||||
"csisolatincyrillic"=>"iso-8859-5",
|
||||
"cyrillic"=>"iso-8859-5",
|
||||
"iso-8859-5"=>"iso-8859-5",
|
||||
"iso-ir-144"=>"iso-8859-5",
|
||||
"iso8859-5"=>"iso-8859-5",
|
||||
"iso88595"=>"iso-8859-5",
|
||||
"iso_8859-5"=>"iso-8859-5",
|
||||
"iso_8859-5:1988"=>"iso-8859-5",
|
||||
"arabic"=>"iso-8859-6",
|
||||
"asmo-708"=>"iso-8859-6",
|
||||
"csiso88596e"=>"iso-8859-6",
|
||||
"csiso88596i"=>"iso-8859-6",
|
||||
"csisolatinarabic"=>"iso-8859-6",
|
||||
"ecma-114"=>"iso-8859-6",
|
||||
"iso-8859-6"=>"iso-8859-6",
|
||||
"iso-8859-6-e"=>"iso-8859-6",
|
||||
"iso-8859-6-i"=>"iso-8859-6",
|
||||
"iso-ir-127"=>"iso-8859-6",
|
||||
"iso8859-6"=>"iso-8859-6",
|
||||
"iso88596"=>"iso-8859-6",
|
||||
"iso_8859-6"=>"iso-8859-6",
|
||||
"iso_8859-6:1987"=>"iso-8859-6",
|
||||
"csisolatingreek"=>"iso-8859-7",
|
||||
"ecma-118"=>"iso-8859-7",
|
||||
"elot_928"=>"iso-8859-7",
|
||||
"greek"=>"iso-8859-7",
|
||||
"greek8"=>"iso-8859-7",
|
||||
"iso-8859-7"=>"iso-8859-7",
|
||||
"iso-ir-126"=>"iso-8859-7",
|
||||
"iso8859-7"=>"iso-8859-7",
|
||||
"iso88597"=>"iso-8859-7",
|
||||
"iso_8859-7"=>"iso-8859-7",
|
||||
"iso_8859-7:1987"=>"iso-8859-7",
|
||||
"sun_eu_greek"=>"iso-8859-7",
|
||||
"csiso88598e"=>"iso-8859-8",
|
||||
"csisolatinhebrew"=>"iso-8859-8",
|
||||
"hebrew"=>"iso-8859-8",
|
||||
"iso-8859-8"=>"iso-8859-8",
|
||||
"iso-8859-8-e"=>"iso-8859-8",
|
||||
"iso-ir-138"=>"iso-8859-8",
|
||||
"iso8859-8"=>"iso-8859-8",
|
||||
"iso88598"=>"iso-8859-8",
|
||||
"iso_8859-8"=>"iso-8859-8",
|
||||
"iso_8859-8:1988"=>"iso-8859-8",
|
||||
"visual"=>"iso-8859-8",
|
||||
"csisolatin6"=>"iso-8859-10",
|
||||
"iso-8859-10"=>"iso-8859-10",
|
||||
"iso-ir-157"=>"iso-8859-10",
|
||||
"iso8859-10"=>"iso-8859-10",
|
||||
"iso885910"=>"iso-8859-10",
|
||||
"l6"=>"iso-8859-10",
|
||||
"latin6"=>"iso-8859-10",
|
||||
"iso-8859-13"=>"iso-8859-13",
|
||||
"iso8859-13"=>"iso-8859-13",
|
||||
"iso885913"=>"iso-8859-13",
|
||||
"iso-8859-14"=>"iso-8859-14",
|
||||
"iso8859-14"=>"iso-8859-14",
|
||||
"iso885914"=>"iso-8859-14",
|
||||
"csisolatin9"=>"iso-8859-15",
|
||||
"iso-8859-15"=>"iso-8859-15",
|
||||
"iso8859-15"=>"iso-8859-15",
|
||||
"iso885915"=>"iso-8859-15",
|
||||
"iso_8859-15"=>"iso-8859-15",
|
||||
"l9"=>"iso-8859-15",
|
||||
"iso-8859-16"=>"iso-8859-16",
|
||||
"cskoi8r"=>"koi8-r",
|
||||
"koi"=>"koi8-r",
|
||||
"koi8"=>"koi8-r",
|
||||
"koi8-r"=>"koi8-r",
|
||||
"koi8_r"=>"koi8-r",
|
||||
"koi8-ru"=>"koi8-u",
|
||||
"koi8-u"=>"koi8-u",
|
||||
"dos-874"=>"windows-874",
|
||||
"iso-8859-11"=>"windows-874",
|
||||
"iso8859-11"=>"windows-874",
|
||||
"iso885911"=>"windows-874",
|
||||
"tis-620"=>"windows-874",
|
||||
"windows-874"=>"windows-874",
|
||||
"cp1250"=>"windows-1250",
|
||||
"windows-1250"=>"windows-1250",
|
||||
"x-cp1250"=>"windows-1250",
|
||||
"cp1251"=>"windows-1251",
|
||||
"windows-1251"=>"windows-1251",
|
||||
"x-cp1251"=>"windows-1251",
|
||||
"ansi_x3.4-1968"=>"windows-1252",
|
||||
"ascii"=>"windows-1252",
|
||||
"cp1252"=>"windows-1252",
|
||||
"cp819"=>"windows-1252",
|
||||
"csisolatin1"=>"windows-1252",
|
||||
"ibm819"=>"windows-1252",
|
||||
"iso-8859-1"=>"windows-1252",
|
||||
"iso-ir-100"=>"windows-1252",
|
||||
"iso8859-1"=>"windows-1252",
|
||||
"iso88591"=>"windows-1252",
|
||||
"iso_8859-1"=>"windows-1252",
|
||||
"iso_8859-1:1987"=>"windows-1252",
|
||||
"l1"=>"windows-1252",
|
||||
"latin1"=>"windows-1252",
|
||||
"us-ascii"=>"windows-1252",
|
||||
"windows-1252"=>"windows-1252",
|
||||
"x-cp1252"=>"windows-1252",
|
||||
"cp1253"=>"windows-1253",
|
||||
"windows-1253"=>"windows-1253",
|
||||
"x-cp1253"=>"windows-1253",
|
||||
"cp1254"=>"windows-1254",
|
||||
"csisolatin5"=>"windows-1254",
|
||||
"iso-8859-9"=>"windows-1254",
|
||||
"iso-ir-148"=>"windows-1254",
|
||||
"iso8859-9"=>"windows-1254",
|
||||
"iso88599"=>"windows-1254",
|
||||
"iso_8859-9"=>"windows-1254",
|
||||
"iso_8859-9:1989"=>"windows-1254",
|
||||
"l5"=>"windows-1254",
|
||||
"latin5"=>"windows-1254",
|
||||
"windows-1254"=>"windows-1254",
|
||||
"x-cp1254"=>"windows-1254",
|
||||
"cp1255"=>"windows-1255",
|
||||
"windows-1255"=>"windows-1255",
|
||||
"x-cp1255"=>"windows-1255",
|
||||
"cp1256"=>"windows-1256",
|
||||
"windows-1256"=>"windows-1256",
|
||||
"x-cp1256"=>"windows-1256",
|
||||
"cp1257"=>"windows-1257",
|
||||
"windows-1257"=>"windows-1257",
|
||||
"x-cp1257"=>"windows-1257",
|
||||
"cp1258"=>"windows-1258",
|
||||
"windows-1258"=>"windows-1258",
|
||||
"x-cp1258"=>"windows-1258",
|
||||
"x-mac-cyrillic"=>"macCyrillic",
|
||||
"x-mac-ukrainian"=>"macCyrillic",
|
||||
"chinese"=>"gbk",
|
||||
"csgb2312"=>"gbk",
|
||||
"csiso58gb231280"=>"gbk",
|
||||
"gb2312"=>"gbk",
|
||||
"gb_2312"=>"gbk",
|
||||
"gb_2312-80"=>"gbk",
|
||||
"gbk"=>"gbk",
|
||||
"iso-ir-58"=>"gbk",
|
||||
"x-gbk"=>"gbk",
|
||||
"gb18030"=>"gb18030",
|
||||
"big5"=>"big5",
|
||||
"big5-hkscs"=>"big5",
|
||||
"cn-big5"=>"big5",
|
||||
"csbig5"=>"big5",
|
||||
"x-x-big5"=>"big5",
|
||||
"cseucpkdfmtjapanese"=>"cp51932",
|
||||
"euc-jp"=>"cp51932",
|
||||
"x-euc-jp"=>"cp51932",
|
||||
"csiso2022jp"=>"cp50221",
|
||||
"iso-2022-jp"=>"cp50221",
|
||||
"csshiftjis"=>"Windows-31J",
|
||||
"ms932"=>"Windows-31J",
|
||||
"ms_kanji"=>"Windows-31J",
|
||||
"shift-jis"=>"Windows-31J",
|
||||
"shift_jis"=>"Windows-31J",
|
||||
"sjis"=>"Windows-31J",
|
||||
"windows-31j"=>"Windows-31J",
|
||||
"x-sjis"=>"Windows-31J",
|
||||
"cseuckr"=>"euc-kr",
|
||||
"csksc56011987"=>"euc-kr",
|
||||
"euc-kr"=>"euc-kr",
|
||||
"iso-ir-149"=>"euc-kr",
|
||||
"korean"=>"euc-kr",
|
||||
"ks_c_5601-1987"=>"euc-kr",
|
||||
"ks_c_5601-1989"=>"euc-kr",
|
||||
"ksc5601"=>"euc-kr",
|
||||
"ksc_5601"=>"euc-kr",
|
||||
"windows-949"=>"euc-kr",
|
||||
"utf-16be"=>"utf-16be",
|
||||
"utf-16"=>"utf-16le",
|
||||
"utf-16le"=>"utf-16le",
|
||||
} # :nodoc:
|
||||
Ractor.make_shareable(WEB_ENCODINGS_) if defined?(Ractor)
|
||||
|
||||
# :nodoc:
|
||||
# return encoding or nil
|
||||
# http://encoding.spec.whatwg.org/#concept-encoding-get
|
||||
def self.get_encoding(label)
|
||||
Encoding.find(WEB_ENCODINGS_[label.to_str.strip.downcase]) rescue nil
|
||||
end
|
||||
end # module Gem::URI
|
||||
|
||||
module Gem
|
||||
|
||||
#
|
||||
# Returns a \Gem::URI object derived from the given +uri+,
|
||||
# which may be a \Gem::URI string or an existing \Gem::URI object:
|
||||
#
|
||||
# # Returns a new Gem::URI.
|
||||
# uri = Gem::URI('http://github.com/ruby/ruby')
|
||||
# # => #<Gem::URI::HTTP http://github.com/ruby/ruby>
|
||||
# # Returns the given Gem::URI.
|
||||
# Gem::URI(uri)
|
||||
# # => #<Gem::URI::HTTP http://github.com/ruby/ruby>
|
||||
#
|
||||
def URI(uri)
|
||||
if uri.is_a?(Gem::URI::Generic)
|
||||
uri
|
||||
elsif uri = String.try_convert(uri)
|
||||
Gem::URI.parse(uri)
|
||||
else
|
||||
raise ArgumentError,
|
||||
"bad argument (expected Gem::URI object or Gem::URI string)"
|
||||
end
|
||||
end
|
||||
module_function :URI
|
||||
end
|
100
lib/rubygems/vendor/uri/lib/uri/file.rb
vendored
Normal file
100
lib/rubygems/vendor/uri/lib/uri/file.rb
vendored
Normal file
@ -0,0 +1,100 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative 'generic'
|
||||
|
||||
module Gem::URI
|
||||
|
||||
#
|
||||
# The "file" Gem::URI is defined by RFC8089.
|
||||
#
|
||||
class File < Generic
|
||||
# A Default port of nil for Gem::URI::File.
|
||||
DEFAULT_PORT = nil
|
||||
|
||||
#
|
||||
# An Array of the available components for Gem::URI::File.
|
||||
#
|
||||
COMPONENT = [
|
||||
:scheme,
|
||||
:host,
|
||||
:path
|
||||
].freeze
|
||||
|
||||
#
|
||||
# == Description
|
||||
#
|
||||
# Creates a new Gem::URI::File object from components, with syntax checking.
|
||||
#
|
||||
# The components accepted are +host+ and +path+.
|
||||
#
|
||||
# The components should be provided either as an Array, or as a Hash
|
||||
# with keys formed by preceding the component names with a colon.
|
||||
#
|
||||
# If an Array is used, the components must be passed in the
|
||||
# order <code>[host, path]</code>.
|
||||
#
|
||||
# A path from e.g. the File class should be escaped before
|
||||
# being passed.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# require 'rubygems/vendor/uri/lib/uri'
|
||||
#
|
||||
# uri1 = Gem::URI::File.build(['host.example.com', '/path/file.zip'])
|
||||
# uri1.to_s # => "file://host.example.com/path/file.zip"
|
||||
#
|
||||
# uri2 = Gem::URI::File.build({:host => 'host.example.com',
|
||||
# :path => '/ruby/src'})
|
||||
# uri2.to_s # => "file://host.example.com/ruby/src"
|
||||
#
|
||||
# uri3 = Gem::URI::File.build({:path => Gem::URI::escape('/path/my file.txt')})
|
||||
# uri3.to_s # => "file:///path/my%20file.txt"
|
||||
#
|
||||
def self.build(args)
|
||||
tmp = Util::make_components_hash(self, args)
|
||||
super(tmp)
|
||||
end
|
||||
|
||||
# Protected setter for the host component +v+.
|
||||
#
|
||||
# See also Gem::URI::Generic.host=.
|
||||
#
|
||||
def set_host(v)
|
||||
v = "" if v.nil? || v == "localhost"
|
||||
@host = v
|
||||
end
|
||||
|
||||
# do nothing
|
||||
def set_port(v)
|
||||
end
|
||||
|
||||
# raise InvalidURIError
|
||||
def check_userinfo(user)
|
||||
raise Gem::URI::InvalidURIError, "can not set userinfo for file Gem::URI"
|
||||
end
|
||||
|
||||
# raise InvalidURIError
|
||||
def check_user(user)
|
||||
raise Gem::URI::InvalidURIError, "can not set user for file Gem::URI"
|
||||
end
|
||||
|
||||
# raise InvalidURIError
|
||||
def check_password(user)
|
||||
raise Gem::URI::InvalidURIError, "can not set password for file Gem::URI"
|
||||
end
|
||||
|
||||
# do nothing
|
||||
def set_userinfo(v)
|
||||
end
|
||||
|
||||
# do nothing
|
||||
def set_user(v)
|
||||
end
|
||||
|
||||
# do nothing
|
||||
def set_password(v)
|
||||
end
|
||||
end
|
||||
|
||||
register_scheme 'FILE', File
|
||||
end
|
267
lib/rubygems/vendor/uri/lib/uri/ftp.rb
vendored
Normal file
267
lib/rubygems/vendor/uri/lib/uri/ftp.rb
vendored
Normal file
@ -0,0 +1,267 @@
|
||||
# frozen_string_literal: false
|
||||
# = uri/ftp.rb
|
||||
#
|
||||
# Author:: Akira Yamada <akira@ruby-lang.org>
|
||||
# License:: You can redistribute it and/or modify it under the same term as Ruby.
|
||||
#
|
||||
# See Gem::URI for general documentation
|
||||
#
|
||||
|
||||
require_relative 'generic'
|
||||
|
||||
module Gem::URI
|
||||
|
||||
#
|
||||
# FTP Gem::URI syntax is defined by RFC1738 section 3.2.
|
||||
#
|
||||
# This class will be redesigned because of difference of implementations;
|
||||
# the structure of its path. draft-hoffman-ftp-uri-04 is a draft but it
|
||||
# is a good summary about the de facto spec.
|
||||
# http://tools.ietf.org/html/draft-hoffman-ftp-uri-04
|
||||
#
|
||||
class FTP < Generic
|
||||
# A Default port of 21 for Gem::URI::FTP.
|
||||
DEFAULT_PORT = 21
|
||||
|
||||
#
|
||||
# An Array of the available components for Gem::URI::FTP.
|
||||
#
|
||||
COMPONENT = [
|
||||
:scheme,
|
||||
:userinfo, :host, :port,
|
||||
:path, :typecode
|
||||
].freeze
|
||||
|
||||
#
|
||||
# Typecode is "a", "i", or "d".
|
||||
#
|
||||
# * "a" indicates a text file (the FTP command was ASCII)
|
||||
# * "i" indicates a binary file (FTP command IMAGE)
|
||||
# * "d" indicates the contents of a directory should be displayed
|
||||
#
|
||||
TYPECODE = ['a', 'i', 'd'].freeze
|
||||
|
||||
# Typecode prefix ";type=".
|
||||
TYPECODE_PREFIX = ';type='.freeze
|
||||
|
||||
def self.new2(user, password, host, port, path,
|
||||
typecode = nil, arg_check = true) # :nodoc:
|
||||
# Do not use this method! Not tested. [Bug #7301]
|
||||
# This methods remains just for compatibility,
|
||||
# Keep it undocumented until the active maintainer is assigned.
|
||||
typecode = nil if typecode.size == 0
|
||||
if typecode && !TYPECODE.include?(typecode)
|
||||
raise ArgumentError,
|
||||
"bad typecode is specified: #{typecode}"
|
||||
end
|
||||
|
||||
# do escape
|
||||
|
||||
self.new('ftp',
|
||||
[user, password],
|
||||
host, port, nil,
|
||||
typecode ? path + TYPECODE_PREFIX + typecode : path,
|
||||
nil, nil, nil, arg_check)
|
||||
end
|
||||
|
||||
#
|
||||
# == Description
|
||||
#
|
||||
# Creates a new Gem::URI::FTP object from components, with syntax checking.
|
||||
#
|
||||
# The components accepted are +userinfo+, +host+, +port+, +path+, and
|
||||
# +typecode+.
|
||||
#
|
||||
# The components should be provided either as an Array, or as a Hash
|
||||
# with keys formed by preceding the component names with a colon.
|
||||
#
|
||||
# If an Array is used, the components must be passed in the
|
||||
# order <code>[userinfo, host, port, path, typecode]</code>.
|
||||
#
|
||||
# If the path supplied is absolute, it will be escaped in order to
|
||||
# make it absolute in the Gem::URI.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# require 'rubygems/vendor/uri/lib/uri'
|
||||
#
|
||||
# uri1 = Gem::URI::FTP.build(['user:password', 'ftp.example.com', nil,
|
||||
# '/path/file.zip', 'i'])
|
||||
# uri1.to_s # => "ftp://user:password@ftp.example.com/%2Fpath/file.zip;type=i"
|
||||
#
|
||||
# uri2 = Gem::URI::FTP.build({:host => 'ftp.example.com',
|
||||
# :path => 'ruby/src'})
|
||||
# uri2.to_s # => "ftp://ftp.example.com/ruby/src"
|
||||
#
|
||||
def self.build(args)
|
||||
|
||||
# Fix the incoming path to be generic URL syntax
|
||||
# FTP path -> URL path
|
||||
# foo/bar /foo/bar
|
||||
# /foo/bar /%2Ffoo/bar
|
||||
#
|
||||
if args.kind_of?(Array)
|
||||
args[3] = '/' + args[3].sub(/^\//, '%2F')
|
||||
else
|
||||
args[:path] = '/' + args[:path].sub(/^\//, '%2F')
|
||||
end
|
||||
|
||||
tmp = Util::make_components_hash(self, args)
|
||||
|
||||
if tmp[:typecode]
|
||||
if tmp[:typecode].size == 1
|
||||
tmp[:typecode] = TYPECODE_PREFIX + tmp[:typecode]
|
||||
end
|
||||
tmp[:path] << tmp[:typecode]
|
||||
end
|
||||
|
||||
return super(tmp)
|
||||
end
|
||||
|
||||
#
|
||||
# == Description
|
||||
#
|
||||
# Creates a new Gem::URI::FTP object from generic URL components with no
|
||||
# syntax checking.
|
||||
#
|
||||
# Unlike build(), this method does not escape the path component as
|
||||
# required by RFC1738; instead it is treated as per RFC2396.
|
||||
#
|
||||
# Arguments are +scheme+, +userinfo+, +host+, +port+, +registry+, +path+,
|
||||
# +opaque+, +query+, and +fragment+, in that order.
|
||||
#
|
||||
def initialize(scheme,
|
||||
userinfo, host, port, registry,
|
||||
path, opaque,
|
||||
query,
|
||||
fragment,
|
||||
parser = nil,
|
||||
arg_check = false)
|
||||
raise InvalidURIError unless path
|
||||
path = path.sub(/^\//,'')
|
||||
path.sub!(/^%2F/,'/')
|
||||
super(scheme, userinfo, host, port, registry, path, opaque,
|
||||
query, fragment, parser, arg_check)
|
||||
@typecode = nil
|
||||
if tmp = @path.index(TYPECODE_PREFIX)
|
||||
typecode = @path[tmp + TYPECODE_PREFIX.size..-1]
|
||||
@path = @path[0..tmp - 1]
|
||||
|
||||
if arg_check
|
||||
self.typecode = typecode
|
||||
else
|
||||
self.set_typecode(typecode)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# typecode accessor.
|
||||
#
|
||||
# See Gem::URI::FTP::COMPONENT.
|
||||
attr_reader :typecode
|
||||
|
||||
# Validates typecode +v+,
|
||||
# returns +true+ or +false+.
|
||||
#
|
||||
def check_typecode(v)
|
||||
if TYPECODE.include?(v)
|
||||
return true
|
||||
else
|
||||
raise InvalidComponentError,
|
||||
"bad typecode(expected #{TYPECODE.join(', ')}): #{v}"
|
||||
end
|
||||
end
|
||||
private :check_typecode
|
||||
|
||||
# Private setter for the typecode +v+.
|
||||
#
|
||||
# See also Gem::URI::FTP.typecode=.
|
||||
#
|
||||
def set_typecode(v)
|
||||
@typecode = v
|
||||
end
|
||||
protected :set_typecode
|
||||
|
||||
#
|
||||
# == Args
|
||||
#
|
||||
# +v+::
|
||||
# String
|
||||
#
|
||||
# == Description
|
||||
#
|
||||
# Public setter for the typecode +v+
|
||||
# (with validation).
|
||||
#
|
||||
# See also Gem::URI::FTP.check_typecode.
|
||||
#
|
||||
# == Usage
|
||||
#
|
||||
# require 'rubygems/vendor/uri/lib/uri'
|
||||
#
|
||||
# uri = Gem::URI.parse("ftp://john@ftp.example.com/my_file.img")
|
||||
# #=> #<Gem::URI::FTP ftp://john@ftp.example.com/my_file.img>
|
||||
# uri.typecode = "i"
|
||||
# uri
|
||||
# #=> #<Gem::URI::FTP ftp://john@ftp.example.com/my_file.img;type=i>
|
||||
#
|
||||
def typecode=(typecode)
|
||||
check_typecode(typecode)
|
||||
set_typecode(typecode)
|
||||
typecode
|
||||
end
|
||||
|
||||
def merge(oth) # :nodoc:
|
||||
tmp = super(oth)
|
||||
if self != tmp
|
||||
tmp.set_typecode(oth.typecode)
|
||||
end
|
||||
|
||||
return tmp
|
||||
end
|
||||
|
||||
# Returns the path from an FTP Gem::URI.
|
||||
#
|
||||
# RFC 1738 specifically states that the path for an FTP Gem::URI does not
|
||||
# include the / which separates the Gem::URI path from the Gem::URI host. Example:
|
||||
#
|
||||
# <code>ftp://ftp.example.com/pub/ruby</code>
|
||||
#
|
||||
# The above Gem::URI indicates that the client should connect to
|
||||
# ftp.example.com then cd to pub/ruby from the initial login directory.
|
||||
#
|
||||
# If you want to cd to an absolute directory, you must include an
|
||||
# escaped / (%2F) in the path. Example:
|
||||
#
|
||||
# <code>ftp://ftp.example.com/%2Fpub/ruby</code>
|
||||
#
|
||||
# This method will then return "/pub/ruby".
|
||||
#
|
||||
def path
|
||||
return @path.sub(/^\//,'').sub(/^%2F/,'/')
|
||||
end
|
||||
|
||||
# Private setter for the path of the Gem::URI::FTP.
|
||||
def set_path(v)
|
||||
super("/" + v.sub(/^\//, "%2F"))
|
||||
end
|
||||
protected :set_path
|
||||
|
||||
# Returns a String representation of the Gem::URI::FTP.
|
||||
def to_s
|
||||
save_path = nil
|
||||
if @typecode
|
||||
save_path = @path
|
||||
@path = @path + TYPECODE_PREFIX + @typecode
|
||||
end
|
||||
str = super
|
||||
if @typecode
|
||||
@path = save_path
|
||||
end
|
||||
|
||||
return str
|
||||
end
|
||||
end
|
||||
|
||||
register_scheme 'FTP', FTP
|
||||
end
|
1588
lib/rubygems/vendor/uri/lib/uri/generic.rb
vendored
Normal file
1588
lib/rubygems/vendor/uri/lib/uri/generic.rb
vendored
Normal file
File diff suppressed because it is too large
Load Diff
125
lib/rubygems/vendor/uri/lib/uri/http.rb
vendored
Normal file
125
lib/rubygems/vendor/uri/lib/uri/http.rb
vendored
Normal file
@ -0,0 +1,125 @@
|
||||
# frozen_string_literal: false
|
||||
# = uri/http.rb
|
||||
#
|
||||
# Author:: Akira Yamada <akira@ruby-lang.org>
|
||||
# License:: You can redistribute it and/or modify it under the same term as Ruby.
|
||||
#
|
||||
# See Gem::URI for general documentation
|
||||
#
|
||||
|
||||
require_relative 'generic'
|
||||
|
||||
module Gem::URI
|
||||
|
||||
#
|
||||
# The syntax of HTTP URIs is defined in RFC1738 section 3.3.
|
||||
#
|
||||
# Note that the Ruby Gem::URI library allows HTTP URLs containing usernames and
|
||||
# passwords. This is not legal as per the RFC, but used to be
|
||||
# supported in Internet Explorer 5 and 6, before the MS04-004 security
|
||||
# update. See <URL:http://support.microsoft.com/kb/834489>.
|
||||
#
|
||||
class HTTP < Generic
|
||||
# A Default port of 80 for Gem::URI::HTTP.
|
||||
DEFAULT_PORT = 80
|
||||
|
||||
# An Array of the available components for Gem::URI::HTTP.
|
||||
COMPONENT = %i[
|
||||
scheme
|
||||
userinfo host port
|
||||
path
|
||||
query
|
||||
fragment
|
||||
].freeze
|
||||
|
||||
#
|
||||
# == Description
|
||||
#
|
||||
# Creates a new Gem::URI::HTTP object from components, with syntax checking.
|
||||
#
|
||||
# The components accepted are userinfo, host, port, path, query, and
|
||||
# fragment.
|
||||
#
|
||||
# The components should be provided either as an Array, or as a Hash
|
||||
# with keys formed by preceding the component names with a colon.
|
||||
#
|
||||
# If an Array is used, the components must be passed in the
|
||||
# order <code>[userinfo, host, port, path, query, fragment]</code>.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# uri = Gem::URI::HTTP.build(host: 'www.example.com', path: '/foo/bar')
|
||||
#
|
||||
# uri = Gem::URI::HTTP.build([nil, "www.example.com", nil, "/path",
|
||||
# "query", 'fragment'])
|
||||
#
|
||||
# Currently, if passed userinfo components this method generates
|
||||
# invalid HTTP URIs as per RFC 1738.
|
||||
#
|
||||
def self.build(args)
|
||||
tmp = Util.make_components_hash(self, args)
|
||||
super(tmp)
|
||||
end
|
||||
|
||||
#
|
||||
# == Description
|
||||
#
|
||||
# Returns the full path for an HTTP request, as required by Net::HTTP::Get.
|
||||
#
|
||||
# If the Gem::URI contains a query, the full path is Gem::URI#path + '?' + Gem::URI#query.
|
||||
# Otherwise, the path is simply Gem::URI#path.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# uri = Gem::URI::HTTP.build(path: '/foo/bar', query: 'test=true')
|
||||
# uri.request_uri # => "/foo/bar?test=true"
|
||||
#
|
||||
def request_uri
|
||||
return unless @path
|
||||
|
||||
url = @query ? "#@path?#@query" : @path.dup
|
||||
url.start_with?(?/.freeze) ? url : ?/ + url
|
||||
end
|
||||
|
||||
#
|
||||
# == Description
|
||||
#
|
||||
# Returns the authority for an HTTP uri, as defined in
|
||||
# https://datatracker.ietf.org/doc/html/rfc3986/#section-3.2.
|
||||
#
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# Gem::URI::HTTP.build(host: 'www.example.com', path: '/foo/bar').authority #=> "www.example.com"
|
||||
# Gem::URI::HTTP.build(host: 'www.example.com', port: 8000, path: '/foo/bar').authority #=> "www.example.com:8000"
|
||||
# Gem::URI::HTTP.build(host: 'www.example.com', port: 80, path: '/foo/bar').authority #=> "www.example.com"
|
||||
#
|
||||
def authority
|
||||
if port == default_port
|
||||
host
|
||||
else
|
||||
"#{host}:#{port}"
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# == Description
|
||||
#
|
||||
# Returns the origin for an HTTP uri, as defined in
|
||||
# https://datatracker.ietf.org/doc/html/rfc6454.
|
||||
#
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# Gem::URI::HTTP.build(host: 'www.example.com', path: '/foo/bar').origin #=> "http://www.example.com"
|
||||
# Gem::URI::HTTP.build(host: 'www.example.com', port: 8000, path: '/foo/bar').origin #=> "http://www.example.com:8000"
|
||||
# Gem::URI::HTTP.build(host: 'www.example.com', port: 80, path: '/foo/bar').origin #=> "http://www.example.com"
|
||||
# Gem::URI::HTTPS.build(host: 'www.example.com', path: '/foo/bar').origin #=> "https://www.example.com"
|
||||
#
|
||||
def origin
|
||||
"#{scheme}://#{authority}"
|
||||
end
|
||||
end
|
||||
|
||||
register_scheme 'HTTP', HTTP
|
||||
end
|
23
lib/rubygems/vendor/uri/lib/uri/https.rb
vendored
Normal file
23
lib/rubygems/vendor/uri/lib/uri/https.rb
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
# frozen_string_literal: false
|
||||
# = uri/https.rb
|
||||
#
|
||||
# Author:: Akira Yamada <akira@ruby-lang.org>
|
||||
# License:: You can redistribute it and/or modify it under the same term as Ruby.
|
||||
#
|
||||
# See Gem::URI for general documentation
|
||||
#
|
||||
|
||||
require_relative 'http'
|
||||
|
||||
module Gem::URI
|
||||
|
||||
# The default port for HTTPS URIs is 443, and the scheme is 'https:' rather
|
||||
# than 'http:'. Other than that, HTTPS URIs are identical to HTTP URIs;
|
||||
# see Gem::URI::HTTP.
|
||||
class HTTPS < HTTP
|
||||
# A Default port of 443 for Gem::URI::HTTPS
|
||||
DEFAULT_PORT = 443
|
||||
end
|
||||
|
||||
register_scheme 'HTTPS', HTTPS
|
||||
end
|
261
lib/rubygems/vendor/uri/lib/uri/ldap.rb
vendored
Normal file
261
lib/rubygems/vendor/uri/lib/uri/ldap.rb
vendored
Normal file
@ -0,0 +1,261 @@
|
||||
# frozen_string_literal: false
|
||||
# = uri/ldap.rb
|
||||
#
|
||||
# Author::
|
||||
# Takaaki Tateishi <ttate@jaist.ac.jp>
|
||||
# Akira Yamada <akira@ruby-lang.org>
|
||||
# License::
|
||||
# Gem::URI::LDAP is copyrighted free software by Takaaki Tateishi and Akira Yamada.
|
||||
# You can redistribute it and/or modify it under the same term as Ruby.
|
||||
#
|
||||
# See Gem::URI for general documentation
|
||||
#
|
||||
|
||||
require_relative 'generic'
|
||||
|
||||
module Gem::URI
|
||||
|
||||
#
|
||||
# LDAP Gem::URI SCHEMA (described in RFC2255).
|
||||
#--
|
||||
# ldap://<host>/<dn>[?<attrs>[?<scope>[?<filter>[?<extensions>]]]]
|
||||
#++
|
||||
class LDAP < Generic
|
||||
|
||||
# A Default port of 389 for Gem::URI::LDAP.
|
||||
DEFAULT_PORT = 389
|
||||
|
||||
# An Array of the available components for Gem::URI::LDAP.
|
||||
COMPONENT = [
|
||||
:scheme,
|
||||
:host, :port,
|
||||
:dn,
|
||||
:attributes,
|
||||
:scope,
|
||||
:filter,
|
||||
:extensions,
|
||||
].freeze
|
||||
|
||||
# Scopes available for the starting point.
|
||||
#
|
||||
# * SCOPE_BASE - the Base DN
|
||||
# * SCOPE_ONE - one level under the Base DN, not including the base DN and
|
||||
# not including any entries under this
|
||||
# * SCOPE_SUB - subtrees, all entries at all levels
|
||||
#
|
||||
SCOPE = [
|
||||
SCOPE_ONE = 'one',
|
||||
SCOPE_SUB = 'sub',
|
||||
SCOPE_BASE = 'base',
|
||||
].freeze
|
||||
|
||||
#
|
||||
# == Description
|
||||
#
|
||||
# Creates a new Gem::URI::LDAP object from components, with syntax checking.
|
||||
#
|
||||
# The components accepted are host, port, dn, attributes,
|
||||
# scope, filter, and extensions.
|
||||
#
|
||||
# The components should be provided either as an Array, or as a Hash
|
||||
# with keys formed by preceding the component names with a colon.
|
||||
#
|
||||
# If an Array is used, the components must be passed in the
|
||||
# order <code>[host, port, dn, attributes, scope, filter, extensions]</code>.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# uri = Gem::URI::LDAP.build({:host => 'ldap.example.com',
|
||||
# :dn => '/dc=example'})
|
||||
#
|
||||
# uri = Gem::URI::LDAP.build(["ldap.example.com", nil,
|
||||
# "/dc=example;dc=com", "query", nil, nil, nil])
|
||||
#
|
||||
def self.build(args)
|
||||
tmp = Util::make_components_hash(self, args)
|
||||
|
||||
if tmp[:dn]
|
||||
tmp[:path] = tmp[:dn]
|
||||
end
|
||||
|
||||
query = []
|
||||
[:extensions, :filter, :scope, :attributes].collect do |x|
|
||||
next if !tmp[x] && query.size == 0
|
||||
query.unshift(tmp[x])
|
||||
end
|
||||
|
||||
tmp[:query] = query.join('?')
|
||||
|
||||
return super(tmp)
|
||||
end
|
||||
|
||||
#
|
||||
# == Description
|
||||
#
|
||||
# Creates a new Gem::URI::LDAP object from generic Gem::URI components as per
|
||||
# RFC 2396. No LDAP-specific syntax checking is performed.
|
||||
#
|
||||
# Arguments are +scheme+, +userinfo+, +host+, +port+, +registry+, +path+,
|
||||
# +opaque+, +query+, and +fragment+, in that order.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# uri = Gem::URI::LDAP.new("ldap", nil, "ldap.example.com", nil, nil,
|
||||
# "/dc=example;dc=com", nil, "query", nil)
|
||||
#
|
||||
# See also Gem::URI::Generic.new.
|
||||
#
|
||||
def initialize(*arg)
|
||||
super(*arg)
|
||||
|
||||
if @fragment
|
||||
raise InvalidURIError, 'bad LDAP URL'
|
||||
end
|
||||
|
||||
parse_dn
|
||||
parse_query
|
||||
end
|
||||
|
||||
# Private method to cleanup +dn+ from using the +path+ component attribute.
|
||||
def parse_dn
|
||||
raise InvalidURIError, 'bad LDAP URL' unless @path
|
||||
@dn = @path[1..-1]
|
||||
end
|
||||
private :parse_dn
|
||||
|
||||
# Private method to cleanup +attributes+, +scope+, +filter+, and +extensions+
|
||||
# from using the +query+ component attribute.
|
||||
def parse_query
|
||||
@attributes = nil
|
||||
@scope = nil
|
||||
@filter = nil
|
||||
@extensions = nil
|
||||
|
||||
if @query
|
||||
attrs, scope, filter, extensions = @query.split('?')
|
||||
|
||||
@attributes = attrs if attrs && attrs.size > 0
|
||||
@scope = scope if scope && scope.size > 0
|
||||
@filter = filter if filter && filter.size > 0
|
||||
@extensions = extensions if extensions && extensions.size > 0
|
||||
end
|
||||
end
|
||||
private :parse_query
|
||||
|
||||
# Private method to assemble +query+ from +attributes+, +scope+, +filter+, and +extensions+.
|
||||
def build_path_query
|
||||
@path = '/' + @dn
|
||||
|
||||
query = []
|
||||
[@extensions, @filter, @scope, @attributes].each do |x|
|
||||
next if !x && query.size == 0
|
||||
query.unshift(x)
|
||||
end
|
||||
@query = query.join('?')
|
||||
end
|
||||
private :build_path_query
|
||||
|
||||
# Returns dn.
|
||||
def dn
|
||||
@dn
|
||||
end
|
||||
|
||||
# Private setter for dn +val+.
|
||||
def set_dn(val)
|
||||
@dn = val
|
||||
build_path_query
|
||||
@dn
|
||||
end
|
||||
protected :set_dn
|
||||
|
||||
# Setter for dn +val+.
|
||||
def dn=(val)
|
||||
set_dn(val)
|
||||
val
|
||||
end
|
||||
|
||||
# Returns attributes.
|
||||
def attributes
|
||||
@attributes
|
||||
end
|
||||
|
||||
# Private setter for attributes +val+.
|
||||
def set_attributes(val)
|
||||
@attributes = val
|
||||
build_path_query
|
||||
@attributes
|
||||
end
|
||||
protected :set_attributes
|
||||
|
||||
# Setter for attributes +val+.
|
||||
def attributes=(val)
|
||||
set_attributes(val)
|
||||
val
|
||||
end
|
||||
|
||||
# Returns scope.
|
||||
def scope
|
||||
@scope
|
||||
end
|
||||
|
||||
# Private setter for scope +val+.
|
||||
def set_scope(val)
|
||||
@scope = val
|
||||
build_path_query
|
||||
@scope
|
||||
end
|
||||
protected :set_scope
|
||||
|
||||
# Setter for scope +val+.
|
||||
def scope=(val)
|
||||
set_scope(val)
|
||||
val
|
||||
end
|
||||
|
||||
# Returns filter.
|
||||
def filter
|
||||
@filter
|
||||
end
|
||||
|
||||
# Private setter for filter +val+.
|
||||
def set_filter(val)
|
||||
@filter = val
|
||||
build_path_query
|
||||
@filter
|
||||
end
|
||||
protected :set_filter
|
||||
|
||||
# Setter for filter +val+.
|
||||
def filter=(val)
|
||||
set_filter(val)
|
||||
val
|
||||
end
|
||||
|
||||
# Returns extensions.
|
||||
def extensions
|
||||
@extensions
|
||||
end
|
||||
|
||||
# Private setter for extensions +val+.
|
||||
def set_extensions(val)
|
||||
@extensions = val
|
||||
build_path_query
|
||||
@extensions
|
||||
end
|
||||
protected :set_extensions
|
||||
|
||||
# Setter for extensions +val+.
|
||||
def extensions=(val)
|
||||
set_extensions(val)
|
||||
val
|
||||
end
|
||||
|
||||
# Checks if Gem::URI has a path.
|
||||
# For Gem::URI::LDAP this will return +false+.
|
||||
def hierarchical?
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
register_scheme 'LDAP', LDAP
|
||||
end
|
22
lib/rubygems/vendor/uri/lib/uri/ldaps.rb
vendored
Normal file
22
lib/rubygems/vendor/uri/lib/uri/ldaps.rb
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
# frozen_string_literal: false
|
||||
# = uri/ldap.rb
|
||||
#
|
||||
# License:: You can redistribute it and/or modify it under the same term as Ruby.
|
||||
#
|
||||
# See Gem::URI for general documentation
|
||||
#
|
||||
|
||||
require_relative 'ldap'
|
||||
|
||||
module Gem::URI
|
||||
|
||||
# The default port for LDAPS URIs is 636, and the scheme is 'ldaps:' rather
|
||||
# than 'ldap:'. Other than that, LDAPS URIs are identical to LDAP URIs;
|
||||
# see Gem::URI::LDAP.
|
||||
class LDAPS < LDAP
|
||||
# A Default port of 636 for Gem::URI::LDAPS
|
||||
DEFAULT_PORT = 636
|
||||
end
|
||||
|
||||
register_scheme 'LDAPS', LDAPS
|
||||
end
|
293
lib/rubygems/vendor/uri/lib/uri/mailto.rb
vendored
Normal file
293
lib/rubygems/vendor/uri/lib/uri/mailto.rb
vendored
Normal file
@ -0,0 +1,293 @@
|
||||
# frozen_string_literal: false
|
||||
# = uri/mailto.rb
|
||||
#
|
||||
# Author:: Akira Yamada <akira@ruby-lang.org>
|
||||
# License:: You can redistribute it and/or modify it under the same term as Ruby.
|
||||
#
|
||||
# See Gem::URI for general documentation
|
||||
#
|
||||
|
||||
require_relative 'generic'
|
||||
|
||||
module Gem::URI
|
||||
|
||||
#
|
||||
# RFC6068, the mailto URL scheme.
|
||||
#
|
||||
class MailTo < Generic
|
||||
include RFC2396_REGEXP
|
||||
|
||||
# A Default port of nil for Gem::URI::MailTo.
|
||||
DEFAULT_PORT = nil
|
||||
|
||||
# An Array of the available components for Gem::URI::MailTo.
|
||||
COMPONENT = [ :scheme, :to, :headers ].freeze
|
||||
|
||||
# :stopdoc:
|
||||
# "hname" and "hvalue" are encodings of an RFC 822 header name and
|
||||
# value, respectively. As with "to", all URL reserved characters must
|
||||
# be encoded.
|
||||
#
|
||||
# "#mailbox" is as specified in RFC 822 [RFC822]. This means that it
|
||||
# consists of zero or more comma-separated mail addresses, possibly
|
||||
# including "phrase" and "comment" components. Note that all URL
|
||||
# reserved characters in "to" must be encoded: in particular,
|
||||
# parentheses, commas, and the percent sign ("%"), which commonly occur
|
||||
# in the "mailbox" syntax.
|
||||
#
|
||||
# Within mailto URLs, the characters "?", "=", "&" are reserved.
|
||||
|
||||
# ; RFC 6068
|
||||
# hfields = "?" hfield *( "&" hfield )
|
||||
# hfield = hfname "=" hfvalue
|
||||
# hfname = *qchar
|
||||
# hfvalue = *qchar
|
||||
# qchar = unreserved / pct-encoded / some-delims
|
||||
# some-delims = "!" / "$" / "'" / "(" / ")" / "*"
|
||||
# / "+" / "," / ";" / ":" / "@"
|
||||
#
|
||||
# ; RFC3986
|
||||
# unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
||||
# pct-encoded = "%" HEXDIG HEXDIG
|
||||
HEADER_REGEXP = /\A(?<hfield>(?:%\h\h|[!$'-.0-;@-Z_a-z~])*=(?:%\h\h|[!$'-.0-;@-Z_a-z~])*)(?:&\g<hfield>)*\z/
|
||||
# practical regexp for email address
|
||||
# https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
|
||||
EMAIL_REGEXP = /\A[a-zA-Z0-9.!\#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\z/
|
||||
# :startdoc:
|
||||
|
||||
#
|
||||
# == Description
|
||||
#
|
||||
# Creates a new Gem::URI::MailTo object from components, with syntax checking.
|
||||
#
|
||||
# Components can be provided as an Array or Hash. If an Array is used,
|
||||
# the components must be supplied as <code>[to, headers]</code>.
|
||||
#
|
||||
# If a Hash is used, the keys are the component names preceded by colons.
|
||||
#
|
||||
# The headers can be supplied as a pre-encoded string, such as
|
||||
# <code>"subject=subscribe&cc=address"</code>, or as an Array of Arrays
|
||||
# like <code>[['subject', 'subscribe'], ['cc', 'address']]</code>.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# require 'rubygems/vendor/uri/lib/uri'
|
||||
#
|
||||
# m1 = Gem::URI::MailTo.build(['joe@example.com', 'subject=Ruby'])
|
||||
# m1.to_s # => "mailto:joe@example.com?subject=Ruby"
|
||||
#
|
||||
# m2 = Gem::URI::MailTo.build(['john@example.com', [['Subject', 'Ruby'], ['Cc', 'jack@example.com']]])
|
||||
# m2.to_s # => "mailto:john@example.com?Subject=Ruby&Cc=jack@example.com"
|
||||
#
|
||||
# m3 = Gem::URI::MailTo.build({:to => 'listman@example.com', :headers => [['subject', 'subscribe']]})
|
||||
# m3.to_s # => "mailto:listman@example.com?subject=subscribe"
|
||||
#
|
||||
def self.build(args)
|
||||
tmp = Util.make_components_hash(self, args)
|
||||
|
||||
case tmp[:to]
|
||||
when Array
|
||||
tmp[:opaque] = tmp[:to].join(',')
|
||||
when String
|
||||
tmp[:opaque] = tmp[:to].dup
|
||||
else
|
||||
tmp[:opaque] = ''
|
||||
end
|
||||
|
||||
if tmp[:headers]
|
||||
query =
|
||||
case tmp[:headers]
|
||||
when Array
|
||||
tmp[:headers].collect { |x|
|
||||
if x.kind_of?(Array)
|
||||
x[0] + '=' + x[1..-1].join
|
||||
else
|
||||
x.to_s
|
||||
end
|
||||
}.join('&')
|
||||
when Hash
|
||||
tmp[:headers].collect { |h,v|
|
||||
h + '=' + v
|
||||
}.join('&')
|
||||
else
|
||||
tmp[:headers].to_s
|
||||
end
|
||||
unless query.empty?
|
||||
tmp[:opaque] << '?' << query
|
||||
end
|
||||
end
|
||||
|
||||
super(tmp)
|
||||
end
|
||||
|
||||
#
|
||||
# == Description
|
||||
#
|
||||
# Creates a new Gem::URI::MailTo object from generic URL components with
|
||||
# no syntax checking.
|
||||
#
|
||||
# This method is usually called from Gem::URI::parse, which checks
|
||||
# the validity of each component.
|
||||
#
|
||||
def initialize(*arg)
|
||||
super(*arg)
|
||||
|
||||
@to = nil
|
||||
@headers = []
|
||||
|
||||
# The RFC3986 parser does not normally populate opaque
|
||||
@opaque = "?#{@query}" if @query && !@opaque
|
||||
|
||||
unless @opaque
|
||||
raise InvalidComponentError,
|
||||
"missing opaque part for mailto URL"
|
||||
end
|
||||
to, header = @opaque.split('?', 2)
|
||||
# allow semicolon as a addr-spec separator
|
||||
# http://support.microsoft.com/kb/820868
|
||||
unless /\A(?:[^@,;]+@[^@,;]+(?:\z|[,;]))*\z/ =~ to
|
||||
raise InvalidComponentError,
|
||||
"unrecognised opaque part for mailtoURL: #{@opaque}"
|
||||
end
|
||||
|
||||
if arg[10] # arg_check
|
||||
self.to = to
|
||||
self.headers = header
|
||||
else
|
||||
set_to(to)
|
||||
set_headers(header)
|
||||
end
|
||||
end
|
||||
|
||||
# The primary e-mail address of the URL, as a String.
|
||||
attr_reader :to
|
||||
|
||||
# E-mail headers set by the URL, as an Array of Arrays.
|
||||
attr_reader :headers
|
||||
|
||||
# Checks the to +v+ component.
|
||||
def check_to(v)
|
||||
return true unless v
|
||||
return true if v.size == 0
|
||||
|
||||
v.split(/[,;]/).each do |addr|
|
||||
# check url safety as path-rootless
|
||||
if /\A(?:%\h\h|[!$&-.0-;=@-Z_a-z~])*\z/ !~ addr
|
||||
raise InvalidComponentError,
|
||||
"an address in 'to' is invalid as Gem::URI #{addr.dump}"
|
||||
end
|
||||
|
||||
# check addr-spec
|
||||
# don't s/\+/ /g
|
||||
addr.gsub!(/%\h\h/, Gem::URI::TBLDECWWWCOMP_)
|
||||
if EMAIL_REGEXP !~ addr
|
||||
raise InvalidComponentError,
|
||||
"an address in 'to' is invalid as uri-escaped addr-spec #{addr.dump}"
|
||||
end
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
private :check_to
|
||||
|
||||
# Private setter for to +v+.
|
||||
def set_to(v)
|
||||
@to = v
|
||||
end
|
||||
protected :set_to
|
||||
|
||||
# Setter for to +v+.
|
||||
def to=(v)
|
||||
check_to(v)
|
||||
set_to(v)
|
||||
v
|
||||
end
|
||||
|
||||
# Checks the headers +v+ component against either
|
||||
# * HEADER_REGEXP
|
||||
def check_headers(v)
|
||||
return true unless v
|
||||
return true if v.size == 0
|
||||
if HEADER_REGEXP !~ v
|
||||
raise InvalidComponentError,
|
||||
"bad component(expected opaque component): #{v}"
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
private :check_headers
|
||||
|
||||
# Private setter for headers +v+.
|
||||
def set_headers(v)
|
||||
@headers = []
|
||||
if v
|
||||
v.split('&').each do |x|
|
||||
@headers << x.split(/=/, 2)
|
||||
end
|
||||
end
|
||||
end
|
||||
protected :set_headers
|
||||
|
||||
# Setter for headers +v+.
|
||||
def headers=(v)
|
||||
check_headers(v)
|
||||
set_headers(v)
|
||||
v
|
||||
end
|
||||
|
||||
# Constructs String from Gem::URI.
|
||||
def to_s
|
||||
@scheme + ':' +
|
||||
if @to
|
||||
@to
|
||||
else
|
||||
''
|
||||
end +
|
||||
if @headers.size > 0
|
||||
'?' + @headers.collect{|x| x.join('=')}.join('&')
|
||||
else
|
||||
''
|
||||
end +
|
||||
if @fragment
|
||||
'#' + @fragment
|
||||
else
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
# Returns the RFC822 e-mail text equivalent of the URL, as a String.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# require 'rubygems/vendor/uri/lib/uri'
|
||||
#
|
||||
# uri = Gem::URI.parse("mailto:ruby-list@ruby-lang.org?Subject=subscribe&cc=myaddr")
|
||||
# uri.to_mailtext
|
||||
# # => "To: ruby-list@ruby-lang.org\nSubject: subscribe\nCc: myaddr\n\n\n"
|
||||
#
|
||||
def to_mailtext
|
||||
to = Gem::URI.decode_www_form_component(@to)
|
||||
head = ''
|
||||
body = ''
|
||||
@headers.each do |x|
|
||||
case x[0]
|
||||
when 'body'
|
||||
body = Gem::URI.decode_www_form_component(x[1])
|
||||
when 'to'
|
||||
to << ', ' + Gem::URI.decode_www_form_component(x[1])
|
||||
else
|
||||
head << Gem::URI.decode_www_form_component(x[0]).capitalize + ': ' +
|
||||
Gem::URI.decode_www_form_component(x[1]) + "\n"
|
||||
end
|
||||
end
|
||||
|
||||
"To: #{to}
|
||||
#{head}
|
||||
#{body}
|
||||
"
|
||||
end
|
||||
alias to_rfc822text to_mailtext
|
||||
end
|
||||
|
||||
register_scheme 'MAILTO', MailTo
|
||||
end
|
539
lib/rubygems/vendor/uri/lib/uri/rfc2396_parser.rb
vendored
Normal file
539
lib/rubygems/vendor/uri/lib/uri/rfc2396_parser.rb
vendored
Normal file
@ -0,0 +1,539 @@
|
||||
# frozen_string_literal: false
|
||||
#--
|
||||
# = uri/common.rb
|
||||
#
|
||||
# Author:: Akira Yamada <akira@ruby-lang.org>
|
||||
# License::
|
||||
# You can redistribute it and/or modify it under the same term as Ruby.
|
||||
#
|
||||
# See Gem::URI for general documentation
|
||||
#
|
||||
|
||||
module Gem::URI
|
||||
#
|
||||
# Includes Gem::URI::REGEXP::PATTERN
|
||||
#
|
||||
module RFC2396_REGEXP
|
||||
#
|
||||
# Patterns used to parse Gem::URI's
|
||||
#
|
||||
module PATTERN
|
||||
# :stopdoc:
|
||||
|
||||
# RFC 2396 (Gem::URI Generic Syntax)
|
||||
# RFC 2732 (IPv6 Literal Addresses in URL's)
|
||||
# RFC 2373 (IPv6 Addressing Architecture)
|
||||
|
||||
# alpha = lowalpha | upalpha
|
||||
ALPHA = "a-zA-Z"
|
||||
# alphanum = alpha | digit
|
||||
ALNUM = "#{ALPHA}\\d"
|
||||
|
||||
# hex = digit | "A" | "B" | "C" | "D" | "E" | "F" |
|
||||
# "a" | "b" | "c" | "d" | "e" | "f"
|
||||
HEX = "a-fA-F\\d"
|
||||
# escaped = "%" hex hex
|
||||
ESCAPED = "%[#{HEX}]{2}"
|
||||
# mark = "-" | "_" | "." | "!" | "~" | "*" | "'" |
|
||||
# "(" | ")"
|
||||
# unreserved = alphanum | mark
|
||||
UNRESERVED = "\\-_.!~*'()#{ALNUM}"
|
||||
# reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
|
||||
# "$" | ","
|
||||
# reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
|
||||
# "$" | "," | "[" | "]" (RFC 2732)
|
||||
RESERVED = ";/?:@&=+$,\\[\\]"
|
||||
|
||||
# domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum
|
||||
DOMLABEL = "(?:[#{ALNUM}](?:[-#{ALNUM}]*[#{ALNUM}])?)"
|
||||
# toplabel = alpha | alpha *( alphanum | "-" ) alphanum
|
||||
TOPLABEL = "(?:[#{ALPHA}](?:[-#{ALNUM}]*[#{ALNUM}])?)"
|
||||
# hostname = *( domainlabel "." ) toplabel [ "." ]
|
||||
HOSTNAME = "(?:#{DOMLABEL}\\.)*#{TOPLABEL}\\.?"
|
||||
|
||||
# :startdoc:
|
||||
end # PATTERN
|
||||
|
||||
# :startdoc:
|
||||
end # REGEXP
|
||||
|
||||
# Class that parses String's into Gem::URI's.
|
||||
#
|
||||
# It contains a Hash set of patterns and Regexp's that match and validate.
|
||||
#
|
||||
class RFC2396_Parser
|
||||
include RFC2396_REGEXP
|
||||
|
||||
#
|
||||
# == Synopsis
|
||||
#
|
||||
# Gem::URI::Parser.new([opts])
|
||||
#
|
||||
# == Args
|
||||
#
|
||||
# The constructor accepts a hash as options for parser.
|
||||
# Keys of options are pattern names of Gem::URI components
|
||||
# and values of options are pattern strings.
|
||||
# The constructor generates set of regexps for parsing URIs.
|
||||
#
|
||||
# You can use the following keys:
|
||||
#
|
||||
# * :ESCAPED (Gem::URI::PATTERN::ESCAPED in default)
|
||||
# * :UNRESERVED (Gem::URI::PATTERN::UNRESERVED in default)
|
||||
# * :DOMLABEL (Gem::URI::PATTERN::DOMLABEL in default)
|
||||
# * :TOPLABEL (Gem::URI::PATTERN::TOPLABEL in default)
|
||||
# * :HOSTNAME (Gem::URI::PATTERN::HOSTNAME in default)
|
||||
#
|
||||
# == Examples
|
||||
#
|
||||
# p = Gem::URI::Parser.new(:ESCAPED => "(?:%[a-fA-F0-9]{2}|%u[a-fA-F0-9]{4})")
|
||||
# u = p.parse("http://example.jp/%uABCD") #=> #<Gem::URI::HTTP http://example.jp/%uABCD>
|
||||
# Gem::URI.parse(u.to_s) #=> raises Gem::URI::InvalidURIError
|
||||
#
|
||||
# s = "http://example.com/ABCD"
|
||||
# u1 = p.parse(s) #=> #<Gem::URI::HTTP http://example.com/ABCD>
|
||||
# u2 = Gem::URI.parse(s) #=> #<Gem::URI::HTTP http://example.com/ABCD>
|
||||
# u1 == u2 #=> true
|
||||
# u1.eql?(u2) #=> false
|
||||
#
|
||||
def initialize(opts = {})
|
||||
@pattern = initialize_pattern(opts)
|
||||
@pattern.each_value(&:freeze)
|
||||
@pattern.freeze
|
||||
|
||||
@regexp = initialize_regexp(@pattern)
|
||||
@regexp.each_value(&:freeze)
|
||||
@regexp.freeze
|
||||
end
|
||||
|
||||
# The Hash of patterns.
|
||||
#
|
||||
# See also Gem::URI::Parser.initialize_pattern.
|
||||
attr_reader :pattern
|
||||
|
||||
# The Hash of Regexp.
|
||||
#
|
||||
# See also Gem::URI::Parser.initialize_regexp.
|
||||
attr_reader :regexp
|
||||
|
||||
# Returns a split Gem::URI against +regexp[:ABS_URI]+.
|
||||
def split(uri)
|
||||
case uri
|
||||
when ''
|
||||
# null uri
|
||||
|
||||
when @regexp[:ABS_URI]
|
||||
scheme, opaque, userinfo, host, port,
|
||||
registry, path, query, fragment = $~[1..-1]
|
||||
|
||||
# Gem::URI-reference = [ absoluteURI | relativeURI ] [ "#" fragment ]
|
||||
|
||||
# absoluteURI = scheme ":" ( hier_part | opaque_part )
|
||||
# hier_part = ( net_path | abs_path ) [ "?" query ]
|
||||
# opaque_part = uric_no_slash *uric
|
||||
|
||||
# abs_path = "/" path_segments
|
||||
# net_path = "//" authority [ abs_path ]
|
||||
|
||||
# authority = server | reg_name
|
||||
# server = [ [ userinfo "@" ] hostport ]
|
||||
|
||||
if !scheme
|
||||
raise InvalidURIError,
|
||||
"bad Gem::URI(absolute but no scheme): #{uri}"
|
||||
end
|
||||
if !opaque && (!path && (!host && !registry))
|
||||
raise InvalidURIError,
|
||||
"bad Gem::URI(absolute but no path): #{uri}"
|
||||
end
|
||||
|
||||
when @regexp[:REL_URI]
|
||||
scheme = nil
|
||||
opaque = nil
|
||||
|
||||
userinfo, host, port, registry,
|
||||
rel_segment, abs_path, query, fragment = $~[1..-1]
|
||||
if rel_segment && abs_path
|
||||
path = rel_segment + abs_path
|
||||
elsif rel_segment
|
||||
path = rel_segment
|
||||
elsif abs_path
|
||||
path = abs_path
|
||||
end
|
||||
|
||||
# Gem::URI-reference = [ absoluteURI | relativeURI ] [ "#" fragment ]
|
||||
|
||||
# relativeURI = ( net_path | abs_path | rel_path ) [ "?" query ]
|
||||
|
||||
# net_path = "//" authority [ abs_path ]
|
||||
# abs_path = "/" path_segments
|
||||
# rel_path = rel_segment [ abs_path ]
|
||||
|
||||
# authority = server | reg_name
|
||||
# server = [ [ userinfo "@" ] hostport ]
|
||||
|
||||
else
|
||||
raise InvalidURIError, "bad Gem::URI(is not Gem::URI?): #{uri}"
|
||||
end
|
||||
|
||||
path = '' if !path && !opaque # (see RFC2396 Section 5.2)
|
||||
ret = [
|
||||
scheme,
|
||||
userinfo, host, port, # X
|
||||
registry, # X
|
||||
path, # Y
|
||||
opaque, # Y
|
||||
query,
|
||||
fragment
|
||||
]
|
||||
return ret
|
||||
end
|
||||
|
||||
#
|
||||
# == Args
|
||||
#
|
||||
# +uri+::
|
||||
# String
|
||||
#
|
||||
# == Description
|
||||
#
|
||||
# Parses +uri+ and constructs either matching Gem::URI scheme object
|
||||
# (File, FTP, HTTP, HTTPS, LDAP, LDAPS, or MailTo) or Gem::URI::Generic.
|
||||
#
|
||||
# == Usage
|
||||
#
|
||||
# p = Gem::URI::Parser.new
|
||||
# p.parse("ldap://ldap.example.com/dc=example?user=john")
|
||||
# #=> #<Gem::URI::LDAP ldap://ldap.example.com/dc=example?user=john>
|
||||
#
|
||||
def parse(uri)
|
||||
Gem::URI.for(*self.split(uri), self)
|
||||
end
|
||||
|
||||
#
|
||||
# == Args
|
||||
#
|
||||
# +uris+::
|
||||
# an Array of Strings
|
||||
#
|
||||
# == Description
|
||||
#
|
||||
# Attempts to parse and merge a set of URIs.
|
||||
#
|
||||
def join(*uris)
|
||||
uris[0] = convert_to_uri(uris[0])
|
||||
uris.inject :merge
|
||||
end
|
||||
|
||||
#
|
||||
# :call-seq:
|
||||
# extract( str )
|
||||
# extract( str, schemes )
|
||||
# extract( str, schemes ) {|item| block }
|
||||
#
|
||||
# == Args
|
||||
#
|
||||
# +str+::
|
||||
# String to search
|
||||
# +schemes+::
|
||||
# Patterns to apply to +str+
|
||||
#
|
||||
# == Description
|
||||
#
|
||||
# Attempts to parse and merge a set of URIs.
|
||||
# If no +block+ given, then returns the result,
|
||||
# else it calls +block+ for each element in result.
|
||||
#
|
||||
# See also Gem::URI::Parser.make_regexp.
|
||||
#
|
||||
def extract(str, schemes = nil)
|
||||
if block_given?
|
||||
str.scan(make_regexp(schemes)) { yield $& }
|
||||
nil
|
||||
else
|
||||
result = []
|
||||
str.scan(make_regexp(schemes)) { result.push $& }
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
# Returns Regexp that is default +self.regexp[:ABS_URI_REF]+,
|
||||
# unless +schemes+ is provided. Then it is a Regexp.union with +self.pattern[:X_ABS_URI]+.
|
||||
def make_regexp(schemes = nil)
|
||||
unless schemes
|
||||
@regexp[:ABS_URI_REF]
|
||||
else
|
||||
/(?=#{Regexp.union(*schemes)}:)#{@pattern[:X_ABS_URI]}/x
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# :call-seq:
|
||||
# escape( str )
|
||||
# escape( str, unsafe )
|
||||
#
|
||||
# == Args
|
||||
#
|
||||
# +str+::
|
||||
# String to make safe
|
||||
# +unsafe+::
|
||||
# Regexp to apply. Defaults to +self.regexp[:UNSAFE]+
|
||||
#
|
||||
# == Description
|
||||
#
|
||||
# Constructs a safe String from +str+, removing unsafe characters,
|
||||
# replacing them with codes.
|
||||
#
|
||||
def escape(str, unsafe = @regexp[:UNSAFE])
|
||||
unless unsafe.kind_of?(Regexp)
|
||||
# perhaps unsafe is String object
|
||||
unsafe = Regexp.new("[#{Regexp.quote(unsafe)}]", false)
|
||||
end
|
||||
str.gsub(unsafe) do
|
||||
us = $&
|
||||
tmp = ''
|
||||
us.each_byte do |uc|
|
||||
tmp << sprintf('%%%02X', uc)
|
||||
end
|
||||
tmp
|
||||
end.force_encoding(Encoding::US_ASCII)
|
||||
end
|
||||
|
||||
#
|
||||
# :call-seq:
|
||||
# unescape( str )
|
||||
# unescape( str, escaped )
|
||||
#
|
||||
# == Args
|
||||
#
|
||||
# +str+::
|
||||
# String to remove escapes from
|
||||
# +escaped+::
|
||||
# Regexp to apply. Defaults to +self.regexp[:ESCAPED]+
|
||||
#
|
||||
# == Description
|
||||
#
|
||||
# Removes escapes from +str+.
|
||||
#
|
||||
def unescape(str, escaped = @regexp[:ESCAPED])
|
||||
enc = str.encoding
|
||||
enc = Encoding::UTF_8 if enc == Encoding::US_ASCII
|
||||
str.gsub(escaped) { [$&[1, 2]].pack('H2').force_encoding(enc) }
|
||||
end
|
||||
|
||||
@@to_s = Kernel.instance_method(:to_s)
|
||||
if @@to_s.respond_to?(:bind_call)
|
||||
def inspect
|
||||
@@to_s.bind_call(self)
|
||||
end
|
||||
else
|
||||
def inspect
|
||||
@@to_s.bind(self).call
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Constructs the default Hash of patterns.
|
||||
def initialize_pattern(opts = {})
|
||||
ret = {}
|
||||
ret[:ESCAPED] = escaped = (opts.delete(:ESCAPED) || PATTERN::ESCAPED)
|
||||
ret[:UNRESERVED] = unreserved = opts.delete(:UNRESERVED) || PATTERN::UNRESERVED
|
||||
ret[:RESERVED] = reserved = opts.delete(:RESERVED) || PATTERN::RESERVED
|
||||
ret[:DOMLABEL] = opts.delete(:DOMLABEL) || PATTERN::DOMLABEL
|
||||
ret[:TOPLABEL] = opts.delete(:TOPLABEL) || PATTERN::TOPLABEL
|
||||
ret[:HOSTNAME] = hostname = opts.delete(:HOSTNAME)
|
||||
|
||||
# RFC 2396 (Gem::URI Generic Syntax)
|
||||
# RFC 2732 (IPv6 Literal Addresses in URL's)
|
||||
# RFC 2373 (IPv6 Addressing Architecture)
|
||||
|
||||
# uric = reserved | unreserved | escaped
|
||||
ret[:URIC] = uric = "(?:[#{unreserved}#{reserved}]|#{escaped})"
|
||||
# uric_no_slash = unreserved | escaped | ";" | "?" | ":" | "@" |
|
||||
# "&" | "=" | "+" | "$" | ","
|
||||
ret[:URIC_NO_SLASH] = uric_no_slash = "(?:[#{unreserved};?:@&=+$,]|#{escaped})"
|
||||
# query = *uric
|
||||
ret[:QUERY] = query = "#{uric}*"
|
||||
# fragment = *uric
|
||||
ret[:FRAGMENT] = fragment = "#{uric}*"
|
||||
|
||||
# hostname = *( domainlabel "." ) toplabel [ "." ]
|
||||
# reg-name = *( unreserved / pct-encoded / sub-delims ) # RFC3986
|
||||
unless hostname
|
||||
ret[:HOSTNAME] = hostname = "(?:[a-zA-Z0-9\\-.]|%\\h\\h)+"
|
||||
end
|
||||
|
||||
# RFC 2373, APPENDIX B:
|
||||
# IPv6address = hexpart [ ":" IPv4address ]
|
||||
# IPv4address = 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT
|
||||
# hexpart = hexseq | hexseq "::" [ hexseq ] | "::" [ hexseq ]
|
||||
# hexseq = hex4 *( ":" hex4)
|
||||
# hex4 = 1*4HEXDIG
|
||||
#
|
||||
# XXX: This definition has a flaw. "::" + IPv4address must be
|
||||
# allowed too. Here is a replacement.
|
||||
#
|
||||
# IPv4address = 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT
|
||||
ret[:IPV4ADDR] = ipv4addr = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"
|
||||
# hex4 = 1*4HEXDIG
|
||||
hex4 = "[#{PATTERN::HEX}]{1,4}"
|
||||
# lastpart = hex4 | IPv4address
|
||||
lastpart = "(?:#{hex4}|#{ipv4addr})"
|
||||
# hexseq1 = *( hex4 ":" ) hex4
|
||||
hexseq1 = "(?:#{hex4}:)*#{hex4}"
|
||||
# hexseq2 = *( hex4 ":" ) lastpart
|
||||
hexseq2 = "(?:#{hex4}:)*#{lastpart}"
|
||||
# IPv6address = hexseq2 | [ hexseq1 ] "::" [ hexseq2 ]
|
||||
ret[:IPV6ADDR] = ipv6addr = "(?:#{hexseq2}|(?:#{hexseq1})?::(?:#{hexseq2})?)"
|
||||
|
||||
# IPv6prefix = ( hexseq1 | [ hexseq1 ] "::" [ hexseq1 ] ) "/" 1*2DIGIT
|
||||
# unused
|
||||
|
||||
# ipv6reference = "[" IPv6address "]" (RFC 2732)
|
||||
ret[:IPV6REF] = ipv6ref = "\\[#{ipv6addr}\\]"
|
||||
|
||||
# host = hostname | IPv4address
|
||||
# host = hostname | IPv4address | IPv6reference (RFC 2732)
|
||||
ret[:HOST] = host = "(?:#{hostname}|#{ipv4addr}|#{ipv6ref})"
|
||||
# port = *digit
|
||||
ret[:PORT] = port = '\d*'
|
||||
# hostport = host [ ":" port ]
|
||||
ret[:HOSTPORT] = hostport = "#{host}(?::#{port})?"
|
||||
|
||||
# userinfo = *( unreserved | escaped |
|
||||
# ";" | ":" | "&" | "=" | "+" | "$" | "," )
|
||||
ret[:USERINFO] = userinfo = "(?:[#{unreserved};:&=+$,]|#{escaped})*"
|
||||
|
||||
# pchar = unreserved | escaped |
|
||||
# ":" | "@" | "&" | "=" | "+" | "$" | ","
|
||||
pchar = "(?:[#{unreserved}:@&=+$,]|#{escaped})"
|
||||
# param = *pchar
|
||||
param = "#{pchar}*"
|
||||
# segment = *pchar *( ";" param )
|
||||
segment = "#{pchar}*(?:;#{param})*"
|
||||
# path_segments = segment *( "/" segment )
|
||||
ret[:PATH_SEGMENTS] = path_segments = "#{segment}(?:/#{segment})*"
|
||||
|
||||
# server = [ [ userinfo "@" ] hostport ]
|
||||
server = "(?:#{userinfo}@)?#{hostport}"
|
||||
# reg_name = 1*( unreserved | escaped | "$" | "," |
|
||||
# ";" | ":" | "@" | "&" | "=" | "+" )
|
||||
ret[:REG_NAME] = reg_name = "(?:[#{unreserved}$,;:@&=+]|#{escaped})+"
|
||||
# authority = server | reg_name
|
||||
authority = "(?:#{server}|#{reg_name})"
|
||||
|
||||
# rel_segment = 1*( unreserved | escaped |
|
||||
# ";" | "@" | "&" | "=" | "+" | "$" | "," )
|
||||
ret[:REL_SEGMENT] = rel_segment = "(?:[#{unreserved};@&=+$,]|#{escaped})+"
|
||||
|
||||
# scheme = alpha *( alpha | digit | "+" | "-" | "." )
|
||||
ret[:SCHEME] = scheme = "[#{PATTERN::ALPHA}][\\-+.#{PATTERN::ALPHA}\\d]*"
|
||||
|
||||
# abs_path = "/" path_segments
|
||||
ret[:ABS_PATH] = abs_path = "/#{path_segments}"
|
||||
# rel_path = rel_segment [ abs_path ]
|
||||
ret[:REL_PATH] = rel_path = "#{rel_segment}(?:#{abs_path})?"
|
||||
# net_path = "//" authority [ abs_path ]
|
||||
ret[:NET_PATH] = net_path = "//#{authority}(?:#{abs_path})?"
|
||||
|
||||
# hier_part = ( net_path | abs_path ) [ "?" query ]
|
||||
ret[:HIER_PART] = hier_part = "(?:#{net_path}|#{abs_path})(?:\\?(?:#{query}))?"
|
||||
# opaque_part = uric_no_slash *uric
|
||||
ret[:OPAQUE_PART] = opaque_part = "#{uric_no_slash}#{uric}*"
|
||||
|
||||
# absoluteURI = scheme ":" ( hier_part | opaque_part )
|
||||
ret[:ABS_URI] = abs_uri = "#{scheme}:(?:#{hier_part}|#{opaque_part})"
|
||||
# relativeURI = ( net_path | abs_path | rel_path ) [ "?" query ]
|
||||
ret[:REL_URI] = rel_uri = "(?:#{net_path}|#{abs_path}|#{rel_path})(?:\\?#{query})?"
|
||||
|
||||
# Gem::URI-reference = [ absoluteURI | relativeURI ] [ "#" fragment ]
|
||||
ret[:URI_REF] = "(?:#{abs_uri}|#{rel_uri})?(?:##{fragment})?"
|
||||
|
||||
ret[:X_ABS_URI] = "
|
||||
(#{scheme}): (?# 1: scheme)
|
||||
(?:
|
||||
(#{opaque_part}) (?# 2: opaque)
|
||||
|
|
||||
(?:(?:
|
||||
//(?:
|
||||
(?:(?:(#{userinfo})@)? (?# 3: userinfo)
|
||||
(?:(#{host})(?::(\\d*))?))? (?# 4: host, 5: port)
|
||||
|
|
||||
(#{reg_name}) (?# 6: registry)
|
||||
)
|
||||
|
|
||||
(?!//)) (?# XXX: '//' is the mark for hostport)
|
||||
(#{abs_path})? (?# 7: path)
|
||||
)(?:\\?(#{query}))? (?# 8: query)
|
||||
)
|
||||
(?:\\#(#{fragment}))? (?# 9: fragment)
|
||||
"
|
||||
|
||||
ret[:X_REL_URI] = "
|
||||
(?:
|
||||
(?:
|
||||
//
|
||||
(?:
|
||||
(?:(#{userinfo})@)? (?# 1: userinfo)
|
||||
(#{host})?(?::(\\d*))? (?# 2: host, 3: port)
|
||||
|
|
||||
(#{reg_name}) (?# 4: registry)
|
||||
)
|
||||
)
|
||||
|
|
||||
(#{rel_segment}) (?# 5: rel_segment)
|
||||
)?
|
||||
(#{abs_path})? (?# 6: abs_path)
|
||||
(?:\\?(#{query}))? (?# 7: query)
|
||||
(?:\\#(#{fragment}))? (?# 8: fragment)
|
||||
"
|
||||
|
||||
ret
|
||||
end
|
||||
|
||||
# Constructs the default Hash of Regexp's.
|
||||
def initialize_regexp(pattern)
|
||||
ret = {}
|
||||
|
||||
# for Gem::URI::split
|
||||
ret[:ABS_URI] = Regexp.new('\A\s*+' + pattern[:X_ABS_URI] + '\s*\z', Regexp::EXTENDED)
|
||||
ret[:REL_URI] = Regexp.new('\A\s*+' + pattern[:X_REL_URI] + '\s*\z', Regexp::EXTENDED)
|
||||
|
||||
# for Gem::URI::extract
|
||||
ret[:URI_REF] = Regexp.new(pattern[:URI_REF])
|
||||
ret[:ABS_URI_REF] = Regexp.new(pattern[:X_ABS_URI], Regexp::EXTENDED)
|
||||
ret[:REL_URI_REF] = Regexp.new(pattern[:X_REL_URI], Regexp::EXTENDED)
|
||||
|
||||
# for Gem::URI::escape/unescape
|
||||
ret[:ESCAPED] = Regexp.new(pattern[:ESCAPED])
|
||||
ret[:UNSAFE] = Regexp.new("[^#{pattern[:UNRESERVED]}#{pattern[:RESERVED]}]")
|
||||
|
||||
# for Generic#initialize
|
||||
ret[:SCHEME] = Regexp.new("\\A#{pattern[:SCHEME]}\\z")
|
||||
ret[:USERINFO] = Regexp.new("\\A#{pattern[:USERINFO]}\\z")
|
||||
ret[:HOST] = Regexp.new("\\A#{pattern[:HOST]}\\z")
|
||||
ret[:PORT] = Regexp.new("\\A#{pattern[:PORT]}\\z")
|
||||
ret[:OPAQUE] = Regexp.new("\\A#{pattern[:OPAQUE_PART]}\\z")
|
||||
ret[:REGISTRY] = Regexp.new("\\A#{pattern[:REG_NAME]}\\z")
|
||||
ret[:ABS_PATH] = Regexp.new("\\A#{pattern[:ABS_PATH]}\\z")
|
||||
ret[:REL_PATH] = Regexp.new("\\A#{pattern[:REL_PATH]}\\z")
|
||||
ret[:QUERY] = Regexp.new("\\A#{pattern[:QUERY]}\\z")
|
||||
ret[:FRAGMENT] = Regexp.new("\\A#{pattern[:FRAGMENT]}\\z")
|
||||
|
||||
ret
|
||||
end
|
||||
|
||||
def convert_to_uri(uri)
|
||||
if uri.is_a?(Gem::URI::Generic)
|
||||
uri
|
||||
elsif uri = String.try_convert(uri)
|
||||
parse(uri)
|
||||
else
|
||||
raise ArgumentError,
|
||||
"bad argument (expected Gem::URI object or Gem::URI string)"
|
||||
end
|
||||
end
|
||||
|
||||
end # class Parser
|
||||
end # module Gem::URI
|
183
lib/rubygems/vendor/uri/lib/uri/rfc3986_parser.rb
vendored
Normal file
183
lib/rubygems/vendor/uri/lib/uri/rfc3986_parser.rb
vendored
Normal file
@ -0,0 +1,183 @@
|
||||
# frozen_string_literal: true
|
||||
module Gem::URI
|
||||
class RFC3986_Parser # :nodoc:
|
||||
# Gem::URI defined in RFC3986
|
||||
HOST = %r[
|
||||
(?<IP-literal>\[(?:
|
||||
(?<IPv6address>
|
||||
(?:\h{1,4}:){6}
|
||||
(?<ls32>\h{1,4}:\h{1,4}
|
||||
| (?<IPv4address>(?<dec-octet>[1-9]\d|1\d{2}|2[0-4]\d|25[0-5]|\d)
|
||||
\.\g<dec-octet>\.\g<dec-octet>\.\g<dec-octet>)
|
||||
)
|
||||
| ::(?:\h{1,4}:){5}\g<ls32>
|
||||
| \h{1,4}?::(?:\h{1,4}:){4}\g<ls32>
|
||||
| (?:(?:\h{1,4}:)?\h{1,4})?::(?:\h{1,4}:){3}\g<ls32>
|
||||
| (?:(?:\h{1,4}:){,2}\h{1,4})?::(?:\h{1,4}:){2}\g<ls32>
|
||||
| (?:(?:\h{1,4}:){,3}\h{1,4})?::\h{1,4}:\g<ls32>
|
||||
| (?:(?:\h{1,4}:){,4}\h{1,4})?::\g<ls32>
|
||||
| (?:(?:\h{1,4}:){,5}\h{1,4})?::\h{1,4}
|
||||
| (?:(?:\h{1,4}:){,6}\h{1,4})?::
|
||||
)
|
||||
| (?<IPvFuture>v\h++\.[!$&-.0-9:;=A-Z_a-z~]++)
|
||||
)\])
|
||||
| \g<IPv4address>
|
||||
| (?<reg-name>(?:%\h\h|[!$&-.0-9;=A-Z_a-z~])*+)
|
||||
]x
|
||||
|
||||
USERINFO = /(?:%\h\h|[!$&-.0-9:;=A-Z_a-z~])*+/
|
||||
|
||||
SCHEME = %r[[A-Za-z][+\-.0-9A-Za-z]*+].source
|
||||
SEG = %r[(?:%\h\h|[!$&-.0-9:;=@A-Z_a-z~/])].source
|
||||
SEG_NC = %r[(?:%\h\h|[!$&-.0-9;=@A-Z_a-z~])].source
|
||||
FRAGMENT = %r[(?:%\h\h|[!$&-.0-9:;=@A-Z_a-z~/?])*+].source
|
||||
|
||||
RFC3986_URI = %r[\A
|
||||
(?<seg>#{SEG}){0}
|
||||
(?<Gem::URI>
|
||||
(?<scheme>#{SCHEME}):
|
||||
(?<hier-part>//
|
||||
(?<authority>
|
||||
(?:(?<userinfo>#{USERINFO.source})@)?
|
||||
(?<host>#{HOST.source.delete(" \n")})
|
||||
(?::(?<port>\d*+))?
|
||||
)
|
||||
(?<path-abempty>(?:/\g<seg>*+)?)
|
||||
| (?<path-absolute>/((?!/)\g<seg>++)?)
|
||||
| (?<path-rootless>(?!/)\g<seg>++)
|
||||
| (?<path-empty>)
|
||||
)
|
||||
(?:\?(?<query>[^\#]*+))?
|
||||
(?:\#(?<fragment>#{FRAGMENT}))?
|
||||
)\z]x
|
||||
|
||||
RFC3986_relative_ref = %r[\A
|
||||
(?<seg>#{SEG}){0}
|
||||
(?<relative-ref>
|
||||
(?<relative-part>//
|
||||
(?<authority>
|
||||
(?:(?<userinfo>#{USERINFO.source})@)?
|
||||
(?<host>#{HOST.source.delete(" \n")}(?<!/))?
|
||||
(?::(?<port>\d*+))?
|
||||
)
|
||||
(?<path-abempty>(?:/\g<seg>*+)?)
|
||||
| (?<path-absolute>/\g<seg>*+)
|
||||
| (?<path-noscheme>#{SEG_NC}++(?:/\g<seg>*+)?)
|
||||
| (?<path-empty>)
|
||||
)
|
||||
(?:\?(?<query>[^#]*+))?
|
||||
(?:\#(?<fragment>#{FRAGMENT}))?
|
||||
)\z]x
|
||||
attr_reader :regexp
|
||||
|
||||
def initialize
|
||||
@regexp = default_regexp.each_value(&:freeze).freeze
|
||||
end
|
||||
|
||||
def split(uri) #:nodoc:
|
||||
begin
|
||||
uri = uri.to_str
|
||||
rescue NoMethodError
|
||||
raise InvalidURIError, "bad Gem::URI(is not Gem::URI?): #{uri.inspect}"
|
||||
end
|
||||
uri.ascii_only? or
|
||||
raise InvalidURIError, "Gem::URI must be ascii only #{uri.dump}"
|
||||
if m = RFC3986_URI.match(uri)
|
||||
query = m["query"]
|
||||
scheme = m["scheme"]
|
||||
opaque = m["path-rootless"]
|
||||
if opaque
|
||||
opaque << "?#{query}" if query
|
||||
[ scheme,
|
||||
nil, # userinfo
|
||||
nil, # host
|
||||
nil, # port
|
||||
nil, # registry
|
||||
nil, # path
|
||||
opaque,
|
||||
nil, # query
|
||||
m["fragment"]
|
||||
]
|
||||
else # normal
|
||||
[ scheme,
|
||||
m["userinfo"],
|
||||
m["host"],
|
||||
m["port"],
|
||||
nil, # registry
|
||||
(m["path-abempty"] ||
|
||||
m["path-absolute"] ||
|
||||
m["path-empty"]),
|
||||
nil, # opaque
|
||||
query,
|
||||
m["fragment"]
|
||||
]
|
||||
end
|
||||
elsif m = RFC3986_relative_ref.match(uri)
|
||||
[ nil, # scheme
|
||||
m["userinfo"],
|
||||
m["host"],
|
||||
m["port"],
|
||||
nil, # registry,
|
||||
(m["path-abempty"] ||
|
||||
m["path-absolute"] ||
|
||||
m["path-noscheme"] ||
|
||||
m["path-empty"]),
|
||||
nil, # opaque
|
||||
m["query"],
|
||||
m["fragment"]
|
||||
]
|
||||
else
|
||||
raise InvalidURIError, "bad Gem::URI(is not Gem::URI?): #{uri.inspect}"
|
||||
end
|
||||
end
|
||||
|
||||
def parse(uri) # :nodoc:
|
||||
Gem::URI.for(*self.split(uri), self)
|
||||
end
|
||||
|
||||
|
||||
def join(*uris) # :nodoc:
|
||||
uris[0] = convert_to_uri(uris[0])
|
||||
uris.inject :merge
|
||||
end
|
||||
|
||||
@@to_s = Kernel.instance_method(:to_s)
|
||||
if @@to_s.respond_to?(:bind_call)
|
||||
def inspect
|
||||
@@to_s.bind_call(self)
|
||||
end
|
||||
else
|
||||
def inspect
|
||||
@@to_s.bind(self).call
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def default_regexp # :nodoc:
|
||||
{
|
||||
SCHEME: %r[\A#{SCHEME}\z]o,
|
||||
USERINFO: %r[\A#{USERINFO}\z]o,
|
||||
HOST: %r[\A#{HOST}\z]o,
|
||||
ABS_PATH: %r[\A/#{SEG}*+\z]o,
|
||||
REL_PATH: %r[\A(?!/)#{SEG}++\z]o,
|
||||
QUERY: %r[\A(?:%\h\h|[!$&-.0-9:;=@A-Z_a-z~/?])*+\z],
|
||||
FRAGMENT: %r[\A#{FRAGMENT}\z]o,
|
||||
OPAQUE: %r[\A(?:[^/].*)?\z],
|
||||
PORT: /\A[\x09\x0a\x0c\x0d ]*+\d*[\x09\x0a\x0c\x0d ]*\z/,
|
||||
}
|
||||
end
|
||||
|
||||
def convert_to_uri(uri)
|
||||
if uri.is_a?(Gem::URI::Generic)
|
||||
uri
|
||||
elsif uri = String.try_convert(uri)
|
||||
parse(uri)
|
||||
else
|
||||
raise ArgumentError,
|
||||
"bad argument (expected Gem::URI object or Gem::URI string)"
|
||||
end
|
||||
end
|
||||
|
||||
end # class Parser
|
||||
end # module Gem::URI
|
6
lib/rubygems/vendor/uri/lib/uri/version.rb
vendored
Normal file
6
lib/rubygems/vendor/uri/lib/uri/version.rb
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
module Gem::URI
|
||||
# :stopdoc:
|
||||
VERSION_CODE = '001300'.freeze
|
||||
VERSION = VERSION_CODE.scan(/../).collect{|n| n.to_i}.join('.').freeze
|
||||
# :startdoc:
|
||||
end
|
83
lib/rubygems/vendor/uri/lib/uri/ws.rb
vendored
Normal file
83
lib/rubygems/vendor/uri/lib/uri/ws.rb
vendored
Normal file
@ -0,0 +1,83 @@
|
||||
# frozen_string_literal: false
|
||||
# = uri/ws.rb
|
||||
#
|
||||
# Author:: Matt Muller <mamuller@amazon.com>
|
||||
# License:: You can redistribute it and/or modify it under the same term as Ruby.
|
||||
#
|
||||
# See Gem::URI for general documentation
|
||||
#
|
||||
|
||||
require_relative 'generic'
|
||||
|
||||
module Gem::URI
|
||||
|
||||
#
|
||||
# The syntax of WS URIs is defined in RFC6455 section 3.
|
||||
#
|
||||
# Note that the Ruby Gem::URI library allows WS URLs containing usernames and
|
||||
# passwords. This is not legal as per the RFC, but used to be
|
||||
# supported in Internet Explorer 5 and 6, before the MS04-004 security
|
||||
# update. See <URL:http://support.microsoft.com/kb/834489>.
|
||||
#
|
||||
class WS < Generic
|
||||
# A Default port of 80 for Gem::URI::WS.
|
||||
DEFAULT_PORT = 80
|
||||
|
||||
# An Array of the available components for Gem::URI::WS.
|
||||
COMPONENT = %i[
|
||||
scheme
|
||||
userinfo host port
|
||||
path
|
||||
query
|
||||
].freeze
|
||||
|
||||
#
|
||||
# == Description
|
||||
#
|
||||
# Creates a new Gem::URI::WS object from components, with syntax checking.
|
||||
#
|
||||
# The components accepted are userinfo, host, port, path, and query.
|
||||
#
|
||||
# The components should be provided either as an Array, or as a Hash
|
||||
# with keys formed by preceding the component names with a colon.
|
||||
#
|
||||
# If an Array is used, the components must be passed in the
|
||||
# order <code>[userinfo, host, port, path, query]</code>.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# uri = Gem::URI::WS.build(host: 'www.example.com', path: '/foo/bar')
|
||||
#
|
||||
# uri = Gem::URI::WS.build([nil, "www.example.com", nil, "/path", "query"])
|
||||
#
|
||||
# Currently, if passed userinfo components this method generates
|
||||
# invalid WS URIs as per RFC 1738.
|
||||
#
|
||||
def self.build(args)
|
||||
tmp = Util.make_components_hash(self, args)
|
||||
super(tmp)
|
||||
end
|
||||
|
||||
#
|
||||
# == Description
|
||||
#
|
||||
# Returns the full path for a WS Gem::URI, as required by Net::HTTP::Get.
|
||||
#
|
||||
# If the Gem::URI contains a query, the full path is Gem::URI#path + '?' + Gem::URI#query.
|
||||
# Otherwise, the path is simply Gem::URI#path.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# uri = Gem::URI::WS.build(path: '/foo/bar', query: 'test=true')
|
||||
# uri.request_uri # => "/foo/bar?test=true"
|
||||
#
|
||||
def request_uri
|
||||
return unless @path
|
||||
|
||||
url = @query ? "#@path?#@query" : @path.dup
|
||||
url.start_with?(?/.freeze) ? url : ?/ + url
|
||||
end
|
||||
end
|
||||
|
||||
register_scheme 'WS', WS
|
||||
end
|
23
lib/rubygems/vendor/uri/lib/uri/wss.rb
vendored
Normal file
23
lib/rubygems/vendor/uri/lib/uri/wss.rb
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
# frozen_string_literal: false
|
||||
# = uri/wss.rb
|
||||
#
|
||||
# Author:: Matt Muller <mamuller@amazon.com>
|
||||
# License:: You can redistribute it and/or modify it under the same term as Ruby.
|
||||
#
|
||||
# See Gem::URI for general documentation
|
||||
#
|
||||
|
||||
require_relative 'ws'
|
||||
|
||||
module Gem::URI
|
||||
|
||||
# The default port for WSS URIs is 443, and the scheme is 'wss:' rather
|
||||
# than 'ws:'. Other than that, WSS URIs are identical to WS URIs;
|
||||
# see Gem::URI::WS.
|
||||
class WSS < WS
|
||||
# A Default port of 443 for Gem::URI::WSS
|
||||
DEFAULT_PORT = 443
|
||||
end
|
||||
|
||||
register_scheme 'WSS', WSS
|
||||
end
|
@ -17,7 +17,7 @@ require "pp"
|
||||
require "rubygems/package"
|
||||
require "shellwords"
|
||||
require "tmpdir"
|
||||
require "uri"
|
||||
require "rubygems/vendor/uri/lib/uri"
|
||||
require "zlib"
|
||||
require "benchmark" # stdlib
|
||||
require_relative "mock_gem_ui"
|
||||
@ -395,7 +395,7 @@ class Gem::TestCase < Test::Unit::TestCase
|
||||
Gem::RemoteFetcher.fetcher = Gem::FakeFetcher.new
|
||||
|
||||
@gem_repo = "http://gems.example.com/"
|
||||
@uri = URI.parse @gem_repo
|
||||
@uri = Gem::URI.parse @gem_repo
|
||||
Gem.sources.replace [@gem_repo]
|
||||
|
||||
Gem.searcher = nil
|
||||
|
@ -489,7 +489,7 @@ class TestGemDependencyInstaller < Gem::TestCase
|
||||
|
||||
# compact index is available
|
||||
compact_index_response = Gem::Net::HTTPResponse.new "1.1", 200, "OK"
|
||||
compact_index_response.uri = URI("http://gems.example.com")
|
||||
compact_index_response.uri = Gem::URI("http://gems.example.com")
|
||||
@fetcher.data["http://gems.example.com/"] = compact_index_response
|
||||
|
||||
# but private local gem not present there
|
||||
|
@ -34,7 +34,7 @@ class TestGemLocalRemoteOptions < Gem::TestCase
|
||||
def test_clear_sources_option
|
||||
@cmd.add_local_remote_options
|
||||
|
||||
s = URI.parse "http://only-gems.example.com/"
|
||||
s = Gem::URI.parse "http://only-gems.example.com/"
|
||||
|
||||
@cmd.handle_options %W[--clear-sources --source #{s}]
|
||||
assert_equal [s.to_s], Gem.sources
|
||||
@ -76,10 +76,10 @@ class TestGemLocalRemoteOptions < Gem::TestCase
|
||||
def test_source_option
|
||||
@cmd.add_source_option
|
||||
|
||||
s1 = URI.parse "http://more-gems.example.com/"
|
||||
s2 = URI.parse "http://even-more-gems.example.com/"
|
||||
s3 = URI.parse "http://other-gems.example.com/some_subdir"
|
||||
s4 = URI.parse "http://more-gems.example.com/" # Intentional duplicate
|
||||
s1 = Gem::URI.parse "http://more-gems.example.com/"
|
||||
s2 = Gem::URI.parse "http://even-more-gems.example.com/"
|
||||
s3 = Gem::URI.parse "http://other-gems.example.com/some_subdir"
|
||||
s4 = Gem::URI.parse "http://more-gems.example.com/" # Intentional duplicate
|
||||
|
||||
original_sources = Gem.sources.dup
|
||||
|
||||
@ -97,7 +97,7 @@ class TestGemLocalRemoteOptions < Gem::TestCase
|
||||
|
||||
original_sources = Gem.sources.dup
|
||||
|
||||
source = URI.parse "http://more-gems.example.com/"
|
||||
source = Gem::URI.parse "http://more-gems.example.com/"
|
||||
@cmd.handle_options %W[-s #{source}]
|
||||
|
||||
original_sources << source
|
||||
|
@ -162,7 +162,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
|
||||
end
|
||||
|
||||
def test_cache_update_path
|
||||
uri = URI "http://example/file"
|
||||
uri = Gem::URI "http://example/file"
|
||||
path = File.join @tempdir, "file"
|
||||
|
||||
fetcher = util_fuck_with_fetcher "hello"
|
||||
@ -176,7 +176,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
|
||||
|
||||
def test_cache_update_path_with_utf8_internal_encoding
|
||||
with_internal_encoding("UTF-8") do
|
||||
uri = URI "http://example/file"
|
||||
uri = Gem::URI "http://example/file"
|
||||
path = File.join @tempdir, "file"
|
||||
data = String.new("\xC8").force_encoding(Encoding::BINARY)
|
||||
|
||||
@ -190,7 +190,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
|
||||
end
|
||||
|
||||
def test_cache_update_path_no_update
|
||||
uri = URI "http://example/file"
|
||||
uri = Gem::URI "http://example/file"
|
||||
path = File.join @tempdir, "file"
|
||||
|
||||
fetcher = util_fuck_with_fetcher "hello"
|
||||
@ -613,7 +613,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
|
||||
nil
|
||||
end
|
||||
|
||||
assert_nil fetcher.fetch_path(URI.parse(@gem_repo), Time.at(0))
|
||||
assert_nil fetcher.fetch_path(Gem::URI.parse(@gem_repo), Time.at(0))
|
||||
end
|
||||
|
||||
def test_implicit_no_proxy
|
||||
@ -671,7 +671,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
|
||||
res
|
||||
end
|
||||
|
||||
data = fetcher.fetch_http URI.parse(url)
|
||||
data = fetcher.fetch_http Gem::URI.parse(url)
|
||||
|
||||
assert_equal "real_path", data
|
||||
end
|
||||
@ -689,7 +689,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
|
||||
end
|
||||
|
||||
e = assert_raise Gem::RemoteFetcher::FetchError do
|
||||
fetcher.fetch_http URI.parse(url)
|
||||
fetcher.fetch_http Gem::URI.parse(url)
|
||||
end
|
||||
|
||||
assert_equal "too many redirects (#{url})", e.message
|
||||
@ -706,7 +706,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
|
||||
end
|
||||
|
||||
e = assert_raise Gem::RemoteFetcher::FetchError do
|
||||
fetcher.fetch_http URI.parse(url)
|
||||
fetcher.fetch_http Gem::URI.parse(url)
|
||||
end
|
||||
|
||||
assert_equal "redirecting but no redirect location was given (#{url})", e.message
|
||||
@ -714,7 +714,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
|
||||
|
||||
def test_fetch_http_with_additional_headers
|
||||
ENV["http_proxy"] = @proxy_uri
|
||||
ENV["no_proxy"] = URI.parse(@server_uri).host
|
||||
ENV["no_proxy"] = Gem::URI.parse(@server_uri).host
|
||||
fetcher = Gem::RemoteFetcher.new nil, nil, { "X-Captain" => "murphy" }
|
||||
@fetcher = fetcher
|
||||
assert_equal "murphy", fetcher.fetch_path(@server_uri)
|
||||
@ -747,7 +747,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
|
||||
s3_uri_signer
|
||||
end
|
||||
|
||||
data = fetcher.fetch_s3 URI.parse(url)
|
||||
data = fetcher.fetch_s3 Gem::URI.parse(url)
|
||||
|
||||
assert_equal "https://my-bucket.s3.#{region}.amazonaws.com/gems/specs.4.8.gz?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=testuser%2F20190624%2F#{region}%2Fs3%2Faws4_request&X-Amz-Date=20190624T050641Z&X-Amz-Expires=86400#{token ? "&X-Amz-Security-Token=" + token : ""}&X-Amz-SignedHeaders=host&X-Amz-Signature=#{signature}", $fetched_uri.to_s
|
||||
assert_equal "success", data
|
||||
@ -893,7 +893,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
|
||||
@fetcher = fetcher
|
||||
|
||||
e = assert_raise Gem::RemoteFetcher::FetchError do
|
||||
fetcher.fetch_s3 URI.parse(url)
|
||||
fetcher.fetch_s3 Gem::URI.parse(url)
|
||||
end
|
||||
|
||||
assert_match expected_message, e.message
|
||||
@ -936,7 +936,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
|
||||
def test_observe_no_proxy_env_single_host
|
||||
use_ui @stub_ui do
|
||||
ENV["http_proxy"] = @proxy_uri
|
||||
ENV["no_proxy"] = URI.parse(@server_uri).host
|
||||
ENV["no_proxy"] = Gem::URI.parse(@server_uri).host
|
||||
fetcher = Gem::RemoteFetcher.new nil
|
||||
@fetcher = fetcher
|
||||
assert_data_from_server fetcher.fetch_path(@server_uri)
|
||||
@ -946,7 +946,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
|
||||
def test_observe_no_proxy_env_list
|
||||
use_ui @stub_ui do
|
||||
ENV["http_proxy"] = @proxy_uri
|
||||
ENV["no_proxy"] = "fakeurl.com, #{URI.parse(@server_uri).host}"
|
||||
ENV["no_proxy"] = "fakeurl.com, #{Gem::URI.parse(@server_uri).host}"
|
||||
fetcher = Gem::RemoteFetcher.new nil
|
||||
@fetcher = fetcher
|
||||
assert_data_from_server fetcher.fetch_path(@server_uri)
|
||||
@ -958,7 +958,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
|
||||
@fetcher = fetcher
|
||||
|
||||
assert_throws :block_called do
|
||||
fetcher.request URI("http://example"), Gem::Net::HTTP::Get do |req|
|
||||
fetcher.request Gem::URI("http://example"), Gem::Net::HTTP::Get do |req|
|
||||
assert_kind_of Gem::Net::HTTPGenericRequest, req
|
||||
throw :block_called
|
||||
end
|
||||
|
@ -34,7 +34,7 @@ class TestGemRequest < Gem::TestCase
|
||||
super
|
||||
|
||||
@proxy_uri = "http://localhost:1234"
|
||||
@uri = URI("http://example")
|
||||
@uri = Gem::URI("http://example")
|
||||
|
||||
@request = make_request @uri, nil, nil, nil
|
||||
end
|
||||
@ -56,7 +56,7 @@ class TestGemRequest < Gem::TestCase
|
||||
def test_initialize_proxy_URI
|
||||
proxy_uri = "http://proxy.example.com"
|
||||
|
||||
request = make_request @uri, nil, nil, URI(proxy_uri)
|
||||
request = make_request @uri, nil, nil, Gem::URI(proxy_uri)
|
||||
|
||||
assert_equal proxy_uri, request.proxy_uri.to_s
|
||||
end
|
||||
@ -77,18 +77,18 @@ class TestGemRequest < Gem::TestCase
|
||||
def test_initialize_proxy_ENV_https
|
||||
ENV["https_proxy"] = @proxy_uri
|
||||
|
||||
request = make_request URI("https://example"), nil, nil, nil
|
||||
request = make_request Gem::URI("https://example"), nil, nil, nil
|
||||
|
||||
proxy = request.proxy_uri
|
||||
|
||||
assert_equal URI(@proxy_uri), proxy
|
||||
assert_equal Gem::URI(@proxy_uri), proxy
|
||||
end
|
||||
|
||||
def test_proxy_ENV
|
||||
ENV["http_proxy"] = "http://proxy"
|
||||
ENV["https_proxy"] = ""
|
||||
|
||||
request = make_request URI("https://example"), nil, nil, nil
|
||||
request = make_request Gem::URI("https://example"), nil, nil, nil
|
||||
|
||||
proxy = request.proxy_uri
|
||||
|
||||
@ -102,7 +102,7 @@ class TestGemRequest < Gem::TestCase
|
||||
def self.get_cert_files
|
||||
[TestGemRequest::PUBLIC_CERT_FILE]
|
||||
end
|
||||
end.create_with_proxy URI("https://example"), nil, nil, nil
|
||||
end.create_with_proxy Gem::URI("https://example"), nil, nil, nil
|
||||
|
||||
Gem::Request.configure_connection_for_https connection, request.cert_files
|
||||
|
||||
@ -121,7 +121,7 @@ class TestGemRequest < Gem::TestCase
|
||||
def self.get_cert_files
|
||||
[TestGemRequest::PUBLIC_CERT_FILE]
|
||||
end
|
||||
end.create_with_proxy URI("https://example"), nil, nil, nil
|
||||
end.create_with_proxy Gem::URI("https://example"), nil, nil, nil
|
||||
|
||||
Gem::Request.configure_connection_for_https connection, request.cert_files
|
||||
|
||||
@ -138,17 +138,17 @@ class TestGemRequest < Gem::TestCase
|
||||
request = make_request @uri, nil, nil, nil
|
||||
proxy = request.proxy_uri
|
||||
|
||||
assert_equal URI(@proxy_uri), proxy
|
||||
assert_equal Gem::URI(@proxy_uri), proxy
|
||||
end
|
||||
|
||||
def test_get_proxy_from_env_https
|
||||
ENV["https_proxy"] = @proxy_uri
|
||||
uri = URI("https://example")
|
||||
uri = Gem::URI("https://example")
|
||||
request = make_request uri, nil, nil, nil
|
||||
|
||||
proxy = request.proxy_uri
|
||||
|
||||
assert_equal URI(@proxy_uri), proxy
|
||||
assert_equal Gem::URI(@proxy_uri), proxy
|
||||
end
|
||||
|
||||
def test_get_proxy_from_env_domain
|
||||
@ -191,7 +191,7 @@ class TestGemRequest < Gem::TestCase
|
||||
end
|
||||
|
||||
def test_fetch
|
||||
uri = Gem::Uri.new(URI.parse("#{@gem_repo}/specs.#{Gem.marshal_version}"))
|
||||
uri = Gem::Uri.new(Gem::URI.parse("#{@gem_repo}/specs.#{Gem.marshal_version}"))
|
||||
response = util_stub_net_http(body: :junk, code: 200) do
|
||||
@request = make_request(uri, Gem::Net::HTTP::Get, nil, nil)
|
||||
|
||||
@ -204,7 +204,7 @@ class TestGemRequest < Gem::TestCase
|
||||
|
||||
def test_fetch_basic_auth
|
||||
Gem.configuration.verbose = :really
|
||||
uri = Gem::Uri.new(URI.parse("https://user:pass@example.rubygems/specs.#{Gem.marshal_version}"))
|
||||
uri = Gem::Uri.new(Gem::URI.parse("https://user:pass@example.rubygems/specs.#{Gem.marshal_version}"))
|
||||
conn = util_stub_net_http(body: :junk, code: 200) do |c|
|
||||
use_ui @ui do
|
||||
@request = make_request(uri, Gem::Net::HTTP::Get, nil, nil)
|
||||
@ -220,7 +220,7 @@ class TestGemRequest < Gem::TestCase
|
||||
|
||||
def test_fetch_basic_auth_encoded
|
||||
Gem.configuration.verbose = :really
|
||||
uri = Gem::Uri.new(URI.parse("https://user:%7BDEScede%7Dpass@example.rubygems/specs.#{Gem.marshal_version}"))
|
||||
uri = Gem::Uri.new(Gem::URI.parse("https://user:%7BDEScede%7Dpass@example.rubygems/specs.#{Gem.marshal_version}"))
|
||||
|
||||
conn = util_stub_net_http(body: :junk, code: 200) do |c|
|
||||
use_ui @ui do
|
||||
@ -237,7 +237,7 @@ class TestGemRequest < Gem::TestCase
|
||||
|
||||
def test_fetch_basic_oauth_encoded
|
||||
Gem.configuration.verbose = :really
|
||||
uri = Gem::Uri.new(URI.parse("https://%7BDEScede%7Dpass:x-oauth-basic@example.rubygems/specs.#{Gem.marshal_version}"))
|
||||
uri = Gem::Uri.new(Gem::URI.parse("https://%7BDEScede%7Dpass:x-oauth-basic@example.rubygems/specs.#{Gem.marshal_version}"))
|
||||
|
||||
conn = util_stub_net_http(body: :junk, code: 200) do |c|
|
||||
use_ui @ui do
|
||||
@ -253,7 +253,7 @@ class TestGemRequest < Gem::TestCase
|
||||
end
|
||||
|
||||
def test_fetch_head
|
||||
uri = Gem::Uri.new(URI.parse("#{@gem_repo}/specs.#{Gem.marshal_version}"))
|
||||
uri = Gem::Uri.new(Gem::URI.parse("#{@gem_repo}/specs.#{Gem.marshal_version}"))
|
||||
response = util_stub_net_http(body: "", code: 200) do |_conn|
|
||||
@request = make_request(uri, Gem::Net::HTTP::Get, nil, nil)
|
||||
@request.fetch
|
||||
@ -264,7 +264,7 @@ class TestGemRequest < Gem::TestCase
|
||||
end
|
||||
|
||||
def test_fetch_unmodified
|
||||
uri = Gem::Uri.new(URI.parse("#{@gem_repo}/specs.#{Gem.marshal_version}"))
|
||||
uri = Gem::Uri.new(Gem::URI.parse("#{@gem_repo}/specs.#{Gem.marshal_version}"))
|
||||
t = Time.utc(2013, 1, 2, 3, 4, 5)
|
||||
conn, response = util_stub_net_http(body: "", code: 304) do |c|
|
||||
@request = make_request(uri, Gem::Net::HTTP::Get, t, nil)
|
||||
|
@ -18,7 +18,7 @@ class TestGemRequestConnectionPool < Gem::TestCase
|
||||
@old_client = Gem::Request::ConnectionPools.client
|
||||
Gem::Request::ConnectionPools.client = FakeHttp
|
||||
|
||||
@proxy = URI "http://proxy.example"
|
||||
@proxy = Gem::URI "http://proxy.example"
|
||||
end
|
||||
|
||||
def teardown
|
||||
@ -49,7 +49,7 @@ class TestGemRequestConnectionPool < Gem::TestCase
|
||||
end
|
||||
|
||||
def test_checkout_same_connection
|
||||
uri = URI.parse("http://example/some_endpoint")
|
||||
uri = Gem::URI.parse("http://example/some_endpoint")
|
||||
|
||||
pools = Gem::Request::ConnectionPools.new nil, []
|
||||
pool = pools.pool_for uri
|
||||
@ -99,7 +99,7 @@ class TestGemRequestConnectionPool < Gem::TestCase
|
||||
def test_net_http_args
|
||||
pools = Gem::Request::ConnectionPools.new nil, []
|
||||
|
||||
net_http_args = pools.send :net_http_args, URI("http://example"), nil
|
||||
net_http_args = pools.send :net_http_args, Gem::URI("http://example"), nil
|
||||
|
||||
assert_equal ["example", 80], net_http_args
|
||||
end
|
||||
@ -107,7 +107,7 @@ class TestGemRequestConnectionPool < Gem::TestCase
|
||||
def test_net_http_args_ipv6
|
||||
pools = Gem::Request::ConnectionPools.new nil, []
|
||||
|
||||
net_http_args = pools.send :net_http_args, URI("http://[::1]"), nil
|
||||
net_http_args = pools.send :net_http_args, Gem::URI("http://[::1]"), nil
|
||||
|
||||
assert_equal ["::1", 80], net_http_args
|
||||
end
|
||||
@ -115,7 +115,7 @@ class TestGemRequestConnectionPool < Gem::TestCase
|
||||
def test_net_http_args_proxy
|
||||
pools = Gem::Request::ConnectionPools.new nil, []
|
||||
|
||||
net_http_args = pools.send :net_http_args, URI("http://example"), @proxy
|
||||
net_http_args = pools.send :net_http_args, Gem::URI("http://example"), @proxy
|
||||
|
||||
assert_equal ["example", 80, "proxy.example", 80, nil, nil], net_http_args
|
||||
end
|
||||
@ -126,7 +126,7 @@ class TestGemRequestConnectionPool < Gem::TestCase
|
||||
|
||||
pools = Gem::Request::ConnectionPools.new nil, []
|
||||
|
||||
net_http_args = pools.send :net_http_args, URI("http://example"), @proxy
|
||||
net_http_args = pools.send :net_http_args, Gem::URI("http://example"), @proxy
|
||||
|
||||
assert_equal ["example", 80, nil, nil], net_http_args
|
||||
ensure
|
||||
@ -134,7 +134,7 @@ class TestGemRequestConnectionPool < Gem::TestCase
|
||||
end
|
||||
|
||||
def test_thread_waits_for_connection
|
||||
uri = URI.parse("http://example/some_endpoint")
|
||||
uri = Gem::URI.parse("http://example/some_endpoint")
|
||||
pools = Gem::Request::ConnectionPools.new nil, []
|
||||
pool = pools.pool_for uri
|
||||
|
||||
|
@ -8,7 +8,7 @@ class TestGemResolver < Gem::TestCase
|
||||
end
|
||||
|
||||
def set(*specs)
|
||||
source = Gem::Source.new URI @gem_repo
|
||||
source = Gem::Source.new Gem::URI @gem_repo
|
||||
|
||||
specs = specs.map do |spec|
|
||||
Gem::Resolver::SpecSpecification.new nil, spec, source
|
||||
|
@ -6,30 +6,30 @@ class TestGemResolverAPISet < Gem::TestCase
|
||||
def setup
|
||||
super
|
||||
|
||||
@dep_uri = URI "#{@gem_repo}info/"
|
||||
@dep_uri = Gem::URI "#{@gem_repo}info/"
|
||||
end
|
||||
|
||||
def test_initialize
|
||||
set = Gem::Resolver::APISet.new
|
||||
|
||||
assert_equal URI("https://index.rubygems.org/info/"), set.dep_uri
|
||||
assert_equal URI("https://index.rubygems.org/"), set.uri
|
||||
assert_equal Gem::Source.new(URI("https://index.rubygems.org")), set.source
|
||||
assert_equal Gem::URI("https://index.rubygems.org/info/"), set.dep_uri
|
||||
assert_equal Gem::URI("https://index.rubygems.org/"), set.uri
|
||||
assert_equal Gem::Source.new(Gem::URI("https://index.rubygems.org")), set.source
|
||||
end
|
||||
|
||||
def test_initialize_deeper_uri
|
||||
set = Gem::Resolver::APISet.new "https://rubygemsserver.com/mygems/info"
|
||||
|
||||
assert_equal URI("https://rubygemsserver.com/mygems/info"), set.dep_uri
|
||||
assert_equal URI("https://rubygemsserver.com/"), set.uri
|
||||
assert_equal Gem::Source.new(URI("https://rubygemsserver.com/")), set.source
|
||||
assert_equal Gem::URI("https://rubygemsserver.com/mygems/info"), set.dep_uri
|
||||
assert_equal Gem::URI("https://rubygemsserver.com/"), set.uri
|
||||
assert_equal Gem::Source.new(Gem::URI("https://rubygemsserver.com/")), set.source
|
||||
end
|
||||
|
||||
def test_initialize_uri
|
||||
set = Gem::Resolver::APISet.new @dep_uri
|
||||
|
||||
assert_equal URI("#{@gem_repo}info/"), set.dep_uri
|
||||
assert_equal URI(@gem_repo.to_s), set.uri
|
||||
assert_equal Gem::URI("#{@gem_repo}info/"), set.dep_uri
|
||||
assert_equal Gem::URI(@gem_repo.to_s), set.uri
|
||||
end
|
||||
|
||||
def test_find_all
|
||||
|
@ -124,7 +124,7 @@ class TestGemResolverAPISpecification < Gem::TestCase
|
||||
fetcher.spec "a", 1
|
||||
end
|
||||
|
||||
dep_uri = URI(@gem_repo) + "info"
|
||||
dep_uri = Gem::URI(@gem_repo) + "info"
|
||||
set = Gem::Resolver::APISet.new dep_uri
|
||||
data = {
|
||||
name: "a",
|
||||
@ -148,7 +148,7 @@ class TestGemResolverAPISpecification < Gem::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
dep_uri = URI(@gem_repo) + "info"
|
||||
dep_uri = Gem::URI(@gem_repo) + "info"
|
||||
set = Gem::Resolver::APISet.new dep_uri
|
||||
data = {
|
||||
name: "j",
|
||||
|
@ -34,7 +34,7 @@ class TestGemResolverBestSet < Gem::TestCase
|
||||
|
||||
set = Gem::Resolver::BestSet.new
|
||||
|
||||
api_uri = URI(@gem_repo)
|
||||
api_uri = Gem::URI(@gem_repo)
|
||||
|
||||
set.sets << Gem::Resolver::APISet.new(api_uri)
|
||||
|
||||
@ -94,7 +94,7 @@ class TestGemResolverBestSet < Gem::TestCase
|
||||
def test_replace_failed_api_set
|
||||
set = Gem::Resolver::BestSet.new
|
||||
|
||||
api_uri = URI(@gem_repo) + "./info/"
|
||||
api_uri = Gem::URI(@gem_repo) + "./info/"
|
||||
api_set = Gem::Resolver::APISet.new api_uri
|
||||
|
||||
set.sets << api_set
|
||||
@ -131,7 +131,7 @@ class TestGemResolverBestSet < Gem::TestCase
|
||||
def test_replace_failed_api_set_uri_with_credentials
|
||||
set = Gem::Resolver::BestSet.new
|
||||
|
||||
api_uri = URI(@gem_repo) + "./info/"
|
||||
api_uri = Gem::URI(@gem_repo) + "./info/"
|
||||
api_uri.user = "user"
|
||||
api_uri.password = "pass"
|
||||
api_set = Gem::Resolver::APISet.new api_uri
|
||||
|
@ -22,7 +22,7 @@ class TestGemSource < Gem::TestCase
|
||||
end
|
||||
|
||||
def test_initialize_invalid_uri
|
||||
assert_raise URI::InvalidURIError do
|
||||
assert_raise Gem::URI::InvalidURIError do
|
||||
Gem::Source.new "git@example:a.git"
|
||||
end
|
||||
end
|
||||
@ -36,7 +36,7 @@ class TestGemSource < Gem::TestCase
|
||||
end
|
||||
|
||||
def test_cache_dir_escapes_windows_paths
|
||||
uri = URI.parse("file:///C:/WINDOWS/Temp/gem_repo")
|
||||
uri = Gem::URI.parse("file:///C:/WINDOWS/Temp/gem_repo")
|
||||
root = Gem.spec_cache_dir
|
||||
cache_dir = @source.cache_dir(uri).gsub(root, "")
|
||||
assert !cache_dir.include?(":"), "#{cache_dir} should not contain a :"
|
||||
@ -44,7 +44,7 @@ class TestGemSource < Gem::TestCase
|
||||
|
||||
def test_dependency_resolver_set_bundler_api
|
||||
response = Gem::Net::HTTPResponse.new "1.1", 200, "OK"
|
||||
response.uri = URI("http://example")
|
||||
response.uri = Gem::URI("http://example")
|
||||
|
||||
@fetcher.data[@gem_repo] = response
|
||||
|
||||
@ -78,7 +78,7 @@ class TestGemSource < Gem::TestCase
|
||||
spec = @source.fetch_spec tuple("a", Gem::Version.new(1), "ruby")
|
||||
assert_equal a1.full_name, spec.full_name
|
||||
|
||||
cache_dir = @source.cache_dir URI.parse(spec_uri)
|
||||
cache_dir = @source.cache_dir Gem::URI.parse(spec_uri)
|
||||
|
||||
cache_file = File.join cache_dir, a1.spec_name
|
||||
|
||||
@ -91,7 +91,7 @@ class TestGemSource < Gem::TestCase
|
||||
spec_uri = "#{@gem_repo}/#{Gem::MARSHAL_SPEC_DIR}#{a1.spec_name}"
|
||||
@fetcher.data["#{spec_uri}.rz"] = nil
|
||||
|
||||
cache_dir = @source.cache_dir URI.parse(spec_uri)
|
||||
cache_dir = @source.cache_dir Gem::URI.parse(spec_uri)
|
||||
FileUtils.mkdir_p cache_dir
|
||||
|
||||
cache_file = File.join cache_dir, a1.spec_name
|
||||
|
@ -289,7 +289,7 @@ class TestGemSourceGit < Gem::TestCase
|
||||
end
|
||||
|
||||
def test_uri
|
||||
assert_equal URI(@repository), @source.uri
|
||||
assert_equal Gem::URI(@repository), @source.uri
|
||||
end
|
||||
|
||||
def test_uri_hash
|
||||
|
@ -37,7 +37,7 @@ class TestGemSourceList < Gem::TestCase
|
||||
|
||||
assert_kind_of Gem::Source, source
|
||||
|
||||
assert_kind_of URI, source.uri
|
||||
assert_kind_of Gem::URI, source.uri
|
||||
assert_equal source.uri.to_s, @uri
|
||||
|
||||
assert_equal [source], sl.sources
|
||||
@ -99,7 +99,7 @@ class TestGemSourceList < Gem::TestCase
|
||||
|
||||
def test_include_eh
|
||||
assert @sl.include?(@uri), "string comparison not working"
|
||||
assert @sl.include?(URI.parse(@uri)), "uri comparison not working"
|
||||
assert @sl.include?(Gem::URI.parse(@uri)), "uri comparison not working"
|
||||
end
|
||||
|
||||
def test_include_matches_a_source
|
||||
|
@ -110,6 +110,6 @@ class TestGemSourceLock < Gem::TestCase
|
||||
remote = Gem::Source.new @gem_repo
|
||||
lock = Gem::Source::Lock.new remote
|
||||
|
||||
assert_equal URI(@gem_repo), lock.uri
|
||||
assert_equal Gem::URI(@gem_repo), lock.uri
|
||||
end
|
||||
end
|
||||
|
@ -22,7 +22,7 @@ class TestGemSourceSubpathProblem < Gem::TestCase
|
||||
|
||||
def test_dependency_resolver_set
|
||||
response = Gem::Net::HTTPResponse.new "1.1", 200, "OK"
|
||||
response.uri = URI("http://example")
|
||||
response.uri = Gem::URI("http://example")
|
||||
|
||||
@fetcher.data["#{@gem_repo}/"] = response
|
||||
|
||||
|
@ -11,7 +11,7 @@ class TestGemSpecFetcher < Gem::TestCase
|
||||
def setup
|
||||
super
|
||||
|
||||
@uri = URI.parse @gem_repo
|
||||
@uri = Gem::URI.parse @gem_repo
|
||||
@source = Gem::Source.new(@uri)
|
||||
|
||||
@sf = Gem::SpecFetcher.new
|
||||
|
@ -19,7 +19,7 @@ class WebauthnListenerTest < Gem::TestCase
|
||||
|
||||
def test_listener_thread_retreives_otp_code
|
||||
thread = Gem::GemcutterUtilities::WebauthnListener.listener_thread(Gem.host, @server)
|
||||
Gem::MockBrowser.get URI("http://localhost:#{@port}?code=xyz")
|
||||
Gem::MockBrowser.get Gem::URI("http://localhost:#{@port}?code=xyz")
|
||||
|
||||
thread.join
|
||||
assert_equal "xyz", thread[:otp]
|
||||
@ -27,7 +27,7 @@ class WebauthnListenerTest < Gem::TestCase
|
||||
|
||||
def test_listener_thread_sets_error
|
||||
thread = Gem::GemcutterUtilities::WebauthnListener.listener_thread(Gem.host, @server)
|
||||
Gem::MockBrowser.post URI("http://localhost:#{@port}?code=xyz")
|
||||
Gem::MockBrowser.post Gem::URI("http://localhost:#{@port}?code=xyz")
|
||||
|
||||
thread.join
|
||||
assert_equal "Security device verification failed: Invalid HTTP method POST received.", thread[:error].message
|
||||
@ -35,13 +35,13 @@ class WebauthnListenerTest < Gem::TestCase
|
||||
|
||||
def test_wait_for_otp_code_get_follows_options
|
||||
wait_for_otp_code
|
||||
assert Gem::MockBrowser.options(URI("http://localhost:#{@port}?code=xyz")).is_a? Gem::Net::HTTPNoContent
|
||||
assert Gem::MockBrowser.get(URI("http://localhost:#{@port}?code=xyz")).is_a? Gem::Net::HTTPOK
|
||||
assert Gem::MockBrowser.options(Gem::URI("http://localhost:#{@port}?code=xyz")).is_a? Gem::Net::HTTPNoContent
|
||||
assert Gem::MockBrowser.get(Gem::URI("http://localhost:#{@port}?code=xyz")).is_a? Gem::Net::HTTPOK
|
||||
end
|
||||
|
||||
def test_wait_for_otp_code_options_request
|
||||
wait_for_otp_code
|
||||
response = Gem::MockBrowser.options URI("http://localhost:#{@port}?code=xyz")
|
||||
response = Gem::MockBrowser.options Gem::URI("http://localhost:#{@port}?code=xyz")
|
||||
|
||||
assert response.is_a? Gem::Net::HTTPNoContent
|
||||
assert_equal Gem.host, response["access-control-allow-origin"]
|
||||
@ -52,7 +52,7 @@ class WebauthnListenerTest < Gem::TestCase
|
||||
|
||||
def test_wait_for_otp_code_get_request
|
||||
wait_for_otp_code
|
||||
response = Gem::MockBrowser.get URI("http://localhost:#{@port}?code=xyz")
|
||||
response = Gem::MockBrowser.get Gem::URI("http://localhost:#{@port}?code=xyz")
|
||||
|
||||
assert response.is_a? Gem::Net::HTTPOK
|
||||
assert_equal "text/plain; charset=utf-8", response["Content-Type"]
|
||||
@ -69,7 +69,7 @@ class WebauthnListenerTest < Gem::TestCase
|
||||
|
||||
def test_wait_for_otp_code_invalid_post_req_method
|
||||
wait_for_otp_code_expect_error_with_message("Security device verification failed: Invalid HTTP method POST received.")
|
||||
response = Gem::MockBrowser.post URI("http://localhost:#{@port}?code=xyz")
|
||||
response = Gem::MockBrowser.post Gem::URI("http://localhost:#{@port}?code=xyz")
|
||||
|
||||
assert response
|
||||
assert response.is_a? Gem::Net::HTTPMethodNotAllowed
|
||||
@ -82,7 +82,7 @@ class WebauthnListenerTest < Gem::TestCase
|
||||
|
||||
def test_wait_for_otp_code_incorrect_path
|
||||
wait_for_otp_code_expect_error_with_message("Security device verification failed: Page at /path not found.")
|
||||
response = Gem::MockBrowser.post URI("http://localhost:#{@port}/path?code=xyz")
|
||||
response = Gem::MockBrowser.post Gem::URI("http://localhost:#{@port}/path?code=xyz")
|
||||
|
||||
assert response.is_a? Gem::Net::HTTPNotFound
|
||||
assert_equal "close", response["Connection"]
|
||||
@ -93,7 +93,7 @@ class WebauthnListenerTest < Gem::TestCase
|
||||
|
||||
def test_wait_for_otp_code_no_params_response
|
||||
wait_for_otp_code_expect_error_with_message("Security device verification failed: Did not receive OTP from https://rubygems.org.")
|
||||
response = Gem::MockBrowser.get URI("http://localhost:#{@port}")
|
||||
response = Gem::MockBrowser.get Gem::URI("http://localhost:#{@port}")
|
||||
|
||||
assert response.is_a? Gem::Net::HTTPBadRequest
|
||||
assert_equal "text/plain; charset=utf-8", response["Content-Type"]
|
||||
@ -107,7 +107,7 @@ class WebauthnListenerTest < Gem::TestCase
|
||||
|
||||
def test_wait_for_otp_code_incorrect_params
|
||||
wait_for_otp_code_expect_error_with_message("Security device verification failed: Did not receive OTP from https://rubygems.org.")
|
||||
response = Gem::MockBrowser.get URI("http://localhost:#{@port}?param=xyz")
|
||||
response = Gem::MockBrowser.get Gem::URI("http://localhost:#{@port}?param=xyz")
|
||||
|
||||
assert response.is_a? Gem::Net::HTTPBadRequest
|
||||
assert_equal "text/plain; charset=utf-8", response["Content-Type"]
|
||||
|
@ -40,16 +40,16 @@ class Gem::FakeFetcher
|
||||
end
|
||||
|
||||
def find_data(path)
|
||||
return Gem.read_binary path.path if URI === path && path.scheme == "file"
|
||||
return Gem.read_binary path.path if Gem::URI === path && path.scheme == "file"
|
||||
|
||||
if URI === path && "URI::#{path.scheme.upcase}" != path.class.name
|
||||
if Gem::URI === path && "Gem::URI::#{path.scheme.upcase}" != path.class.name
|
||||
raise ArgumentError,
|
||||
"mismatch for scheme #{path.scheme} and class #{path.class}"
|
||||
end
|
||||
|
||||
path = path.to_s
|
||||
@paths << path
|
||||
raise ArgumentError, "need full URI" unless path.start_with?("https://", "http://")
|
||||
raise ArgumentError, "need full Gem::URI" unless path.start_with?("https://", "http://")
|
||||
|
||||
unless @data.key? path
|
||||
raise Gem::RemoteFetcher::FetchError.new("no data for #{path}", path)
|
||||
@ -194,7 +194,7 @@ end
|
||||
# Example:
|
||||
#
|
||||
# # Sends a get request to http://localhost:5678
|
||||
# Gem::MockBrowser.get URI("http://localhost:5678")
|
||||
# Gem::MockBrowser.get Gem::URI("http://localhost:5678")
|
||||
#
|
||||
# See RubyGems' tests for more examples of MockBrowser.
|
||||
#
|
||||
@ -368,12 +368,12 @@ class Gem::TestCase::SpecFetcherSetup
|
||||
begin
|
||||
gem_repo = @test.gem_repo
|
||||
@test.gem_repo = @repository
|
||||
@test.uri = URI @repository
|
||||
@test.uri = Gem::URI @repository
|
||||
|
||||
@test.util_setup_spec_fetcher(*@downloaded)
|
||||
ensure
|
||||
@test.gem_repo = gem_repo
|
||||
@test.uri = URI gem_repo
|
||||
@test.uri = Gem::URI gem_repo
|
||||
end
|
||||
|
||||
@gems.each do |spec, gem|
|
||||
|
Loading…
x
Reference in New Issue
Block a user