Skip to content

Instantly share code, notes, and snippets.

@yukioc
Created February 19, 2011 16:00
Show Gist options
  • Select an option

  • Save yukioc/835144 to your computer and use it in GitHub Desktop.

Select an option

Save yukioc/835144 to your computer and use it in GitHub Desktop.
decode encoded-URL avoid broken words.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<textarea id="input" cols="40">
%25E3%2581%25AB%25E3%2581%258F%25E3%25
</textarea><br/>
<input type=button value="decodeURI"
onclick="decURI('input')" />
<script>
function decURI(n){
var s=document.getElementById(n).value;
s=s.replace(/%(?:25)+([0-9A-F][0-9A-F])/g,function(whole,m1){
return "%"+m1;
});
var utf8uri = new RegExp(
"%[0-7][0-9A-F]|"+
"%C[2-9A-F]%[89AB][0-9A-F]|%D[0-9A-F]%[89AB][0-9A-F]|"+
"%E[0-F](?:%[89AB][0-9A-F]){2}|"+
"%F[0-7](?:%[89AB][0-9A-F]){3}|"+
"%F[89AB](?:%[89AB][0-9A-F]){4}|"+
"%F[CD](?:%[89AB][0-9A-F]){5}","ig");
s=s.replace(utf8uri,function(whole){
return decodeURI(whole);
});
document.getElementById(n).value = s;
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment