module Bundler::URI

def self._decode_uri_component(regexp, str, enc)

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

def self._encode_uri_component(regexp, table, str, enc)

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

def self.decode_uri_component(str, enc=Encoding::UTF_8)

This does not decode + to SP.

Decodes given +str+ of URL-encoded data.
def self.decode_uri_component(str, enc=Encoding::UTF_8)
  _decode_uri_component(/%\h\h/, str, enc)
end

def self.decode_www_form(str, enc=Encoding::UTF_8, separator: '&', use__charset_: false, isindex: false)

See Bundler::URI.decode_www_form_component, Bundler::URI.encode_www_form.

Hash[ary] #=> {"a"=>"2", "b"=>"3"}
ary.rassoc('a').last #=> '2'
ary.assoc('b').last #=> '3'
ary.assoc('a').last #=> '1'
ary #=> [['a', '1'], ['a', '2'], ['b', '3']]
ary = Bundler::URI.decode_www_form("a=1&a=2&b=3")

so this supports only &-separator, and doesn't support ;-separator.
This refers http://url.spec.whatwg.org/#concept-urlencoded-parser,

and returns an array of key-value arrays.
This decodes application/x-www-form-urlencoded data

Decodes URL-encoded form data from given +str+.
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

def self.decode_www_form_component(str, enc=Encoding::UTF_8)

See Bundler::URI.encode_www_form_component, Bundler::URI.decode_www_form.

This decodes + to SP.

Decodes given +str+ of URL-encoded form data.
def self.decode_www_form_component(str, enc=Encoding::UTF_8)
  _decode_uri_component(/\+|%\h\h/, str, enc)
end

def self.encode_uri_component(str, enc=nil)

This encodes SP to %20 instead of +.

Encodes +str+ using URL encoding
def self.encode_uri_component(str, enc=nil)
  _encode_uri_component(/[^*\-.0-9A-Z_a-z]/, TBLENCURICOMP_, str, enc)
end

def self.encode_www_form(enum, enc=nil)

See Bundler::URI.encode_www_form_component, Bundler::URI.decode_www_form.

#=> "q=ruby&q=perl&lang=en"
Bundler::URI.encode_www_form([["q", "ruby"], ["q", "perl"], ["lang", "en"]])
#=> "q=ruby&q=perl&lang=en"
Bundler::URI.encode_www_form("q" => ["ruby", "perl"], "lang" => "en")
#=> "q=ruby&lang=en"
Bundler::URI.encode_www_form("q" => "ruby", "lang" => "en")
#=> "q=ruby&lang=en"
Bundler::URI.encode_www_form([["q", "ruby"], ["lang", "en"]])

This refers https://url.spec.whatwg.org/#concept-urlencoded-serializer

multipart/form-data.
This method doesn't handle files. When you send a file, use

ASCII incompatible encoding are converted to UTF-8.)
encoding or mixed encoding data. (Strings which are encoded in an HTML5
before calling this method if you want to send data as other than original
This method doesn't convert the encoding of given items, so convert them

This internally uses Bundler::URI.encode_www_form_component(str).

from given an Enumerable object.
This generates application/x-www-form-urlencoded data defined in HTML5

Generates URL-encoded form data from given +enum+.
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

def self.encode_www_form_component(str, enc=nil)

See Bundler::URI.decode_www_form_component, Bundler::URI.encode_www_form.

https://www.w3.org/TR/2013/CR-html5-20130806/forms.html#url-encoded-form-data.
This is an implementation of

If +enc+ is given, convert +str+ to the encoding before percent encoding.

(ASCII space) to + and converts others to %XX.
This method doesn't convert *, -, ., 0-9, A-Z, _, a-z, but does convert SP

Encodes given +str+ to URL-encoded form data.
def self.encode_www_form_component(str, enc=nil)
  _encode_uri_component(/[^*\-.0-9A-Z_a-z]/, TBLENCWWWCOMP_, str, enc)
end

def self.extract(str, schemes = nil, &block)


# => ["http://foo.example.com/bla", "mailto:test@example.com"]
Bundler::URI.extract("text here http://foo.example.org/bla and here mailto:test@example.com and here also.")

require "bundler/vendor/uri/lib/uri"

== Usage

Returns nil if block given or array with matches.
Extracts URIs from a string. If block given, iterates through all matched URIs.

== Description

Limit Bundler::URI matching to specific schemes.
+schemes+::
String to extract URIs from.
+str+::

== Args

Bundler::URI::extract(str[, schemes][,&blk])

== Synopsis
def self.extract(str, schemes = nil, &block)
  warn "Bundler::URI.extract is obsolete", uplevel: 1 if $VERBOSE
  DEFAULT_PARSER.extract(str, schemes, &block)
end

def self.for(scheme, *arguments, default: Generic)


from +Bundler::URI.scheme_list+.
Construct a Bundler::URI instance, using the scheme to detect the appropriate class
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

def self.get_encoding(label)

http://encoding.spec.whatwg.org/#concept-encoding-get
return encoding or nil
:nodoc:
def self.get_encoding(label)
  Encoding.find(WEB_ENCODINGS_[label.to_str.strip.downcase]) rescue nil
end

def self.join(*str)


# => #
Bundler::URI.join('http://example.com', '/foo/', 'bar')

# => #
Bundler::URI.join('http://example.com', '/foo', 'bar')

# => #
Bundler::URI.join('http://example.com', '/foo', '/bar')

# => #
Bundler::URI.join('http://example.com', 'foo')

# => #
Bundler::URI.join("http://example.com/","main.rbx")

require 'bundler/vendor/uri/lib/uri'

== Usage

Joins URIs.

== Description

String(s) to work with, will be converted to RFC3986 URIs before merging.
+str+::

== Args

Bundler::URI::join(str[, str, ...])

== Synopsis
def self.join(*str)
  RFC3986_PARSER.join(*str)
end

def self.parse(uri)


invalid Bundler::URI characters.
It's recommended to first ::escape the provided +uri_str+ if there are any

# => "www.ruby-lang.org"
uri.host
# => "http"
uri.scheme
# => #
uri = Bundler::URI.parse("http://www.ruby-lang.org/")

require 'bundler/vendor/uri/lib/uri'

== Usage

Raised if Bundler::URI given is not a correct one.
Bundler::URI::InvalidURIError::

== Raises

Creates one of the Bundler::URI's subclasses instance from the string.

== Description

String with Bundler::URI.
+uri_str+::

== Args

Bundler::URI::parse(uri_str)

== Synopsis
def self.parse(uri)
  RFC3986_PARSER.parse(uri)
end

def self.regexp(schemes = nil)


end
p $&
html_string.scan(Bundler::URI.regexp) do |*matches|
# You should not rely on the number of parentheses

html_string.sub(Bundler::URI.regexp(['ftp']), '')
# remove ftp URIs

html_string.slice(Bundler::URI.regexp)
# extract first Bundler::URI from html_string

require 'bundler/vendor/uri/lib/uri'

== Usage

number of capture group (parentheses). Never rely on its number.
The Regexp object returned by this method includes arbitrary
Returns a Regexp object which matches to Bundler::URI-like strings.

== Description

whose scheme is one of the match_schemes.
Array of schemes. If given, resulting regexp matches to URIs
+match_schemes+::

== Args

Bundler::URI::regexp([match_schemes])

== Synopsis
def self.regexp(schemes = nil)
  warn "Bundler::URI.regexp is obsolete", uplevel: 1 if $VERBOSE
  DEFAULT_PARSER.make_regexp(schemes)
end

def self.register_scheme(scheme, klass)


can be registered (no -/+/. allowed).
Note that currently only schemes which after .upcase are valid constant names
Register the given +klass+ to be instantiated when parsing URLs with the given +scheme+.
def self.register_scheme(scheme, klass)
  Schemes.const_set(scheme.to_s.upcase, klass)
end

def self.scheme_list

Returns a Hash of the defined schemes.
def self.scheme_list
  Schemes.constants.map { |name|
    [name.to_s.upcase, Schemes.const_get(name)]
  }.to_h
end

def self.split(uri)


# => ["http", nil, "www.ruby-lang.org", nil, nil, "/", nil, nil, nil]
Bundler::URI.split("http://www.ruby-lang.org/")

require 'bundler/vendor/uri/lib/uri'

== Usage

* Fragment
* Query
* Opaque
* Path
* Registry
* Port
* Host
* Userinfo
* Scheme

Splits the string on following parts and returns array with result:

== Description

String with Bundler::URI.
+uri+::

== Args

Bundler::URI::split(uri)

== Synopsis
def self.split(uri)
  RFC3986_PARSER.split(uri)
end