module Bundler::URI
def self.decode_www_form(str, enc=Encoding::UTF_8, separator: '&', use__charset_: false, isindex: false)
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