module Bundler::URI

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


# => [["foo", "0"], ["bar", "1"], ["baz", ""]]
Bundler::URI.decode_www_form('foo=0--bar=1--baz', separator: '--')

A different separator may be specified:

# => [["foo", "0"], ["", ""], ["bar", "1"], ["", ""], ["baz", "2"]]
Bundler::URI.decode_www_form('foo=0&&bar=1&&baz=2')

The given string may contain consecutive separators:

# => [["f#o", "/"], ["b-r", "$"], ["b z", "@"]]
Bundler::URI.decode_www_form('f%23o=%2F&b-r=%24&b+z=%40')

similar to those performed in Bundler::URI.decode_www_form_component:
The returned strings have certain conversions,

# => [["foo", "0"], ["bar", "1"], ["baz", ""]]
Bundler::URI.decode_www_form('foo=0&bar=1&baz')

A simple example:

{String#scrub}[https://docs.ruby-lang.org/en/master/String.html#method-i-scrub].
and has had invalid characters removed via
Each returned string has encoding +enc+,
each subarray is a name/value pair (both are strings).
The returned data is an array of 2-element subarrays;

for which res['Content-Type'] is 'application/x-www-form-urlencoded'.
The method may be used to decode the body of Net::HTTPResponse object +res+

which must be an ASCII string.
Returns name/value pairs derived from the given string +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