I have trying to decode Recursively encoded url . But for even valid URL it is giving error .
I am calling
decodeURIRecursively({},"https%3A%2F%2Fgmail.com%3Frate%3D95%25")
It should return "https://gmail.com?rate=95%" But return string.
If I modify code and change catch block to return url it works well for this scenario but for malformed URL like decodeURIRecursively({},'%E0%A4%A')
. It gives same url .
const decodeURIRecursively = (req, url) => {
// Early return on missing required parameter
if (!req || !url) {
return '';
}
try {
while (decodeURIComponent(url) !== url) {
url = decodeURIComponent(url);
}
} catch (e) {
return ''; // Return empty string as it is not a safe string to decode and use in
}
return url;
};
console.log(decodeURIRecursively({},"https%3A%2F%2Fgmail.com%3Frate%3D95%25"));