Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
var uriCleanup = function (str) {
    var cln = function (str) {
        try {
            str = decodeURIComponent(str);
            //try to decode the URI again
            return cln(str);
        } catch (e) {
           console.log(e)
           //if error thrown, URI contains single percent symbol
           //return the str as it was the last time it was decoded
           return str;
        }
    };
  
    return cln(str);
};
encodedURI = "www.thesite.com?var1=1%252526var2=false%26var3%26search=my%20search%20term%5D";
doubleEncodedURI = "www.thesite.com?var1=1%2526var2=false%2526var3%2526search=my%2520search%2520term%255D%255D";
console.log("encodedURI ", uriCleanup(encodedURI));
console.log("doubleEncodedURI ", uriCleanup(doubleEncodedURI));
console.log("%25 ", uriCleanup("%25"));
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers