decodeURI not fully working
the url looks as it was encoded twice, I also suggest to use decodeURIComponent
decodeURIComponent(decodeURIComponent("http%253a%252f%252fsandbox.yoyogames.com%252fgames%252f171985-h-a-m-heroic-armies-marching"))
results in: "http://sandbox.yoyogames.com/games/171985-h-a-m-heroic-armies-marching"
but you should check why you have the url encoded twice in advance
My implementation is a recursive function:
export function tryDecodeURLComponent(str: string, maxInterations = 30, iterations = 0): string {
if (iterations >= maxInterations) {
return str;
} else if (typeof str === 'string' && (str.indexOf('%3D') !== -1 || str.indexOf('%25') !== -1)) {
return tryDecodeURLComponent(decodeURIComponent(str), maxInterations, iterations + 1)
}
return decodeURIComponent(str);
}
str
: encoded string.maxInterations
: Maximum recursive iterations to try decodingstr
(default:30
).iterations
: Flag counter iteration.