From 65f0a75ee52980bf8c4138c7acbb95616725beca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Wed, 4 Dec 2019 17:59:21 +0100 Subject: [PATCH] We might not need to vendor these --- lib/bundler/vendor/uri/lib/uri.rb | 16 +- lib/bundler/vendor/uri/lib/uri/ftp.rb | 267 -------------------- lib/bundler/vendor/uri/lib/uri/ldap.rb | 261 -------------------- lib/bundler/vendor/uri/lib/uri/ldaps.rb | 21 -- lib/bundler/vendor/uri/lib/uri/mailto.rb | 294 ----------------------- 5 files changed, 6 insertions(+), 853 deletions(-) delete mode 100644 lib/bundler/vendor/uri/lib/uri/ftp.rb delete mode 100644 lib/bundler/vendor/uri/lib/uri/ldap.rb delete mode 100644 lib/bundler/vendor/uri/lib/uri/ldaps.rb delete mode 100644 lib/bundler/vendor/uri/lib/uri/mailto.rb diff --git a/lib/bundler/vendor/uri/lib/uri.rb b/lib/bundler/vendor/uri/lib/uri.rb index 00c01bd07bf..d3bf09ea2d9 100644 --- a/lib/bundler/vendor/uri/lib/uri.rb +++ b/lib/bundler/vendor/uri/lib/uri.rb @@ -92,13 +92,9 @@ module Bundler::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 'bundler/vendor/uri/lib/uri/version' +require 'bundler/vendor/uri/lib/uri/common' +require 'bundler/vendor/uri/lib/uri/generic' +require 'bundler/vendor/uri/lib/uri/file' +require 'bundler/vendor/uri/lib/uri/http' +require 'bundler/vendor/uri/lib/uri/https' diff --git a/lib/bundler/vendor/uri/lib/uri/ftp.rb b/lib/bundler/vendor/uri/lib/uri/ftp.rb deleted file mode 100644 index ad39f57d7b6..00000000000 --- a/lib/bundler/vendor/uri/lib/uri/ftp.rb +++ /dev/null @@ -1,267 +0,0 @@ -# frozen_string_literal: false -# = uri/ftp.rb -# -# Author:: Akira Yamada -# License:: You can redistribute it and/or modify it under the same term as Ruby. -# Revision:: $Id$ -# -# See Bundler::URI for general documentation -# - -require_relative 'generic' - -module Bundler::URI - - # - # FTP Bundler::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 Bundler::URI::FTP. - DEFAULT_PORT = 21 - - # - # An Array of the available components for Bundler::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 Bundler::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 [userinfo, host, port, path, typecode]. - # - # If the path supplied is absolute, it will be escaped in order to - # make it absolute in the Bundler::URI. - # - # Examples: - # - # require 'bundler/vendor/uri/lib/uri' - # - # uri1 = Bundler::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 = Bundler::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 Bundler::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 Bundler::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 Bundler::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 Bundler::URI::FTP.check_typecode. - # - # == Usage - # - # require 'bundler/vendor/uri/lib/uri' - # - # uri = Bundler::URI.parse("ftp://john@ftp.example.com/my_file.img") - # #=> # - # uri.typecode = "i" - # uri - # #=> # - # - 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 Bundler::URI. - # - # RFC 1738 specifically states that the path for an FTP Bundler::URI does not - # include the / which separates the Bundler::URI path from the Bundler::URI host. Example: - # - # ftp://ftp.example.com/pub/ruby - # - # The above Bundler::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: - # - # ftp://ftp.example.com/%2Fpub/ruby - # - # This method will then return "/pub/ruby". - # - def path - return @path.sub(/^\//,'').sub(/^%2F/,'/') - end - - # Private setter for the path of the Bundler::URI::FTP. - def set_path(v) - super("/" + v.sub(/^\//, "%2F")) - end - protected :set_path - - # Returns a String representation of the Bundler::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 - @@schemes['FTP'] = FTP -end diff --git a/lib/bundler/vendor/uri/lib/uri/ldap.rb b/lib/bundler/vendor/uri/lib/uri/ldap.rb deleted file mode 100644 index b707bedb971..00000000000 --- a/lib/bundler/vendor/uri/lib/uri/ldap.rb +++ /dev/null @@ -1,261 +0,0 @@ -# frozen_string_literal: false -# = uri/ldap.rb -# -# Author:: -# Takaaki Tateishi -# Akira Yamada -# License:: -# Bundler::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. -# Revision:: $Id$ -# -# See Bundler::URI for general documentation -# - -require_relative 'generic' - -module Bundler::URI - - # - # LDAP Bundler::URI SCHEMA (described in RFC2255). - #-- - # ldap:///[?[?[?[?]]]] - #++ - class LDAP < Generic - - # A Default port of 389 for Bundler::URI::LDAP. - DEFAULT_PORT = 389 - - # An Array of the available components for Bundler::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 Bundler::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 [host, port, dn, attributes, scope, filter, extensions]. - # - # Example: - # - # uri = Bundler::URI::LDAP.build({:host => 'ldap.example.com', - # :dn => '/dc=example'}) - # - # uri = Bundler::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 Bundler::URI::LDAP object from generic Bundler::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 = Bundler::URI::LDAP.new("ldap", nil, "ldap.example.com", nil, nil, - # "/dc=example;dc=com", nil, "query", nil) - # - # See also Bundler::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 - @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 Bundler::URI has a path. - # For Bundler::URI::LDAP this will return +false+. - def hierarchical? - false - end - end - - @@schemes['LDAP'] = LDAP -end diff --git a/lib/bundler/vendor/uri/lib/uri/ldaps.rb b/lib/bundler/vendor/uri/lib/uri/ldaps.rb deleted file mode 100644 index 0af35bb16b4..00000000000 --- a/lib/bundler/vendor/uri/lib/uri/ldaps.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: false -# = uri/ldap.rb -# -# License:: You can redistribute it and/or modify it under the same term as Ruby. -# -# See Bundler::URI for general documentation -# - -require_relative 'ldap' - -module Bundler::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 Bundler::URI::LDAP. - class LDAPS < LDAP - # A Default port of 636 for Bundler::URI::LDAPS - DEFAULT_PORT = 636 - end - @@schemes['LDAPS'] = LDAPS -end diff --git a/lib/bundler/vendor/uri/lib/uri/mailto.rb b/lib/bundler/vendor/uri/lib/uri/mailto.rb deleted file mode 100644 index 5b2a4765c81..00000000000 --- a/lib/bundler/vendor/uri/lib/uri/mailto.rb +++ /dev/null @@ -1,294 +0,0 @@ -# frozen_string_literal: false -# = uri/mailto.rb -# -# Author:: Akira Yamada -# License:: You can redistribute it and/or modify it under the same term as Ruby. -# Revision:: $Id$ -# -# See Bundler::URI for general documentation -# - -require_relative 'generic' - -module Bundler::URI - - # - # RFC6068, the mailto URL scheme. - # - class MailTo < Generic - include REGEXP - - # A Default port of nil for Bundler::URI::MailTo. - DEFAULT_PORT = nil - - # An Array of the available components for Bundler::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(?(?:%\h\h|[!$'-.0-;@-Z_a-z~])*=(?:%\h\h|[!$'-.0-;@-Z_a-z~])*)(?:&\g)*\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 Bundler::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 [to, headers]. - # - # 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 - # "subject=subscribe&cc=address", or as an Array of Arrays - # like [['subject', 'subscribe'], ['cc', 'address']]. - # - # Examples: - # - # require 'bundler/vendor/uri/lib/uri' - # - # m1 = Bundler::URI::MailTo.build(['joe@example.com', 'subject=Ruby']) - # m1.to_s # => "mailto:joe@example.com?subject=Ruby" - # - # m2 = Bundler::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 = Bundler::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 Bundler::URI::MailTo object from generic URL components with - # no syntax checking. - # - # This method is usually called from Bundler::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 Bundler::URI #{addr.dump}" - end - - # check addr-spec - # don't s/\+/ /g - addr.gsub!(/%\h\h/, Bundler::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 Bundler::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 'bundler/vendor/uri/lib/uri' - # - # uri = Bundler::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 = Bundler::URI.decode_www_form_component(@to) - head = '' - body = '' - @headers.each do |x| - case x[0] - when 'body' - body = Bundler::URI.decode_www_form_component(x[1]) - when 'to' - to << ', ' + Bundler::URI.decode_www_form_component(x[1]) - else - head << Bundler::URI.decode_www_form_component(x[0]).capitalize + ': ' + - Bundler::URI.decode_www_form_component(x[1]) + "\n" - end - end - - "To: #{to} -#{head} -#{body} -" - end - alias to_rfc822text to_mailtext - end - - @@schemes['MAILTO'] = MailTo -end