DecodeURI does not work fully

I am trying to remove the URI encoding from a link, but decodeURI does not seem to work completely.

My link example: /linkout?remoteUrl=http%253a%252f%252fsandbox.yoyogames.com%252fgames%252f171985-ham-heroic-armies-marching

After running the JavaScript script, it looks like this:

 http%3a%2f%2fsandbox.yoyogames.com%2fgames%2f171985-ham-heroic-armies-marching 

How can I get rid of the remaining invalid codes in the URI?

My decoding code:

 var href = $(this).attr('href'); // get the href var href = decodeURI(href.substring(19)); // remove the outgoing part and remove the escaping $(this).attr('href', 'http://'+href) // change link on page 
+6
source share
2 answers

url looks like it was twice encoded, I also suggest using decodeURIComponent

 decodeURIComponent(decodeURIComponent("http%253a%252f%252fsandbox.yoyogames.com%252fgames%252f171985-ham-heroic-armies-marching")) 

leads to: "http://sandbox.yoyogames.com/games/171985-ham-heroic-armies-marching"

but you should check why you have the URL encoded twice.

+22
source

I just encountered this situation in the ASHX handler for the verb PUT. ASP.NET seems to be encoding my XML for me, so my server call HttpUtility.UrlEncode is not needed. Correcting it by calling Javascript decodeURI twice on the client side - closes the barn door after the cows have already left, and the HTTP that I sent was a protocol violation.

I would comment and add that Tobias Krog answered, but I have no points to do this ...

However, I still find it important to note that the disclaimer discussed here is not a Javascript decodeURI or anything else - it is a data validation error.

+1
source

Source: https://habr.com/ru/post/919648/


All Articles