urldecode in ruby?

How do I transform

www.bestbuy.com/site/Electronics\Audio\abcat0200000.c=3fid=3dabcat0200000

into its original format?

www.bestbuy.com/site/Electronics/Audio/abcat0200000.c?id=abcat0200000

Is there a urldecode?


Solution 1:

A better method is CGI.unescape:
URI.unescape is deprecated

decoded_uri = CGI.unescape(encoded_uri)

Solution 2:

Via decode:

require 'uri'
URI.decode(encoded_uri)

Ruby 2.7 and above:

require 'uri'
URI.decode_www_form_component(encoded_uri)

Solution 3:

The equivalent of PHP's urldecode in Ruby is CGI::unescape.