Created
March 23, 2017 23:00
-
-
Save yannick/97bfd1c516807231c96a7ac7ad44cfdc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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