I entered the following in Chrome's console:
decodeURIComponent('a%AFc');
Instead of resulting to a0xAFc
, it caused a URIError exception (malformed uri).
I've heard several excuses why this may be possible, but what I don't understand is why?
The decodeURIComponent()
function in particular is supposed to decode data, not verify the URI.
In order to fix "Uncaught URIError: URI malformed" errors in your code, you need to ensure that you are passing valid characters to both encodeURI and decodeURI too. If you would like to convert Unicode code points to UTF8, you can use this online tool.
The JavaScript exception "malformed URI sequence" occurs when URI encoding or decoding wasn't successful.
The URIError object represents an error when a global URI handling function was used in a wrong way. URIError is a serializable object, so it can be cloned with structuredClone() or copied between Workers using postMessage() .
The decodeURIComponent() function decodes a Uniform Resource Identifier (URI) component previously created by encodeURIComponent or by a similar routine.
%AF
is not a character on his own but part of Unicode sequence (MACRON - %C2%AF
).
%AF
wasn't produced by encodeURIComponent
but something like escape
, so it can be decoded by unescape
.
What you probably need is decodeURIComponent('%C2%AF')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With