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

后端 未结 7 1172
别那么骄傲
别那么骄傲 2020-12-31 05:11

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

alert(decodeURI(\'%\'));

or

alert(encodeURIC         


        
7条回答
  •  北海茫月
    2020-12-31 05:26

    The endless-loop or lock up may be due to a bug in jquery.

    You can set a breakpoint in jquery at a point which is likely causing the 'lock-up'.

    Decode doesn't make sense with just % provided, as percent-encoding is followed by alphanumericals referring to a given character in the ASCII table, and should normally yield an URIError in Opera, Chrome, FF.

    Use the browser built in function encodeURI if you are looking for the 'url-encoded' notation of the percent-character:

    encodeURI('%')
    //>"%25"
    

提交回复
热议问题