End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
CGI::Util#unescape
unescape(string,encoding=@@accept_charset)
lib/cgi/util.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.0.5/lib/cgi/util.rb, line 22
def unescape(string,encoding=@@accept_charset)
str=string.tr('+', ' ').b.gsub(/((?:%[0-9a-fA-F]{2})+)/) do |m|
[m.delete('%')].pack('H*')
end.force_encoding(encoding)
str.valid_encoding? ? str : str.force_encoding(string.encoding)
end
URL-decode a string with encoding(optional).
Example
string = CGI.unescape("%27Stop%21%27+said+Fred") # => "'Stop!' said Fred"