javascriptdecodeuricomponent

Why does decodeURIComponent('%') lock up my browser?


I was just testing something with AJAX and I found that on success if I alert

alert(decodeURI('%'));

or

alert(encodeURIComponent('%'));

the browser errors out with the following code.

$.ajax({
   type: "POST",
   url: "some.php",
   data: "",
   success: function(html){
         alert(decodeURIComponent('%'));
//           alert(decodeURI('%'));
   }
 });

If I use any other string it works just fine.
Is it something that I missed?


Solution

  • Chrome barfs when trying from the console. It gives an URIError: URI malformed. The % is an escape character, it can't be on its own.