Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

urldecode in ruby?

Tags:

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?

like image 720
wefwgeweg Avatar asked Apr 28 '10 20:04

wefwgeweg


People also ask

What is Urldecode?

The urldecode() function is an inbuilt function in PHP which is used to decode url which is encoded by encoded() function. Syntax: string urldecode( $input ) Parameters: This function accepts single parameter $input which holds the url to be decoded. Return Value: This function returns the decoded string on success.

What is meant by Urlencode and Urldecode?

urlencode () is the function that can be used conveniently to encode a string before using in a query part of a URL. This is a convenient way for passing variables to the next page. urldecode() is the function that is used to decode the encoded string.

What is Urldecode C#?

UrlDecode(String) Converts a string that has been encoded for transmission in a URL into a decoded string.


2 Answers

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

decoded_uri = CGI.unescape(encoded_uri) 
like image 148
merqlove Avatar answered Oct 23 '22 09:10

merqlove


Via decode:

require 'uri' URI.decode(encoded_uri) 

Ruby 2.7 and above:

require 'uri' URI.decode_www_form_component(encoded_uri) 
like image 25
tokhi Avatar answered Oct 23 '22 10:10

tokhi