Skip to content

Instantly share code, notes, and snippets.

@yannick
Created March 23, 2017 23:00
Show Gist options
  • Select an option

  • Save yannick/97bfd1c516807231c96a7ac7ad44cfdc to your computer and use it in GitHub Desktop.

Select an option

Save yannick/97bfd1c516807231c96a7ac7ad44cfdc to your computer and use it in GitHub Desktop.
#mruby ghetto PORT from https://ruby-doc.org/stdlib-1.9.3/libdoc/cgi/rdoc/CGI.html#method-c-parse
module CGI
def self.parse(query)
params = {}
query.split(/[&;]/).each do |pairs|
key, value = pairs.split('=',2).collect{|v| CGI::unescape(v) }
if key && value
params.has_key?(key) ? params[key].push(value) : params[key] = [value]
elsif key
params[key]=[]
end
end
params.default=[].freeze
params
end
def self.unescape(string)
str=string.gsub(/\+/, ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/) do
[$1.delete('%')].pack('H*')
end
str
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment