forgive me for my bumbling confusion. I am learning javascript and got
caught up in a gotcha. this may be due to Mozillas spidermonkey or
most likely to my n00b mindset on how encodeURI* and decodeURI* work.
Can we all agree that this does *not* work:
decodeURI("http://domain.com%");
Can we all agree that this *does* work:
decodeURI("http://domain.com");
here is where the confusion settles in. decodeURI has no problems with
simply ignoring the second example (which is not even encoded) and
producing exactly what it was given but considers the first example a
malformed URI and returns a URIError. maybe I am the dumb one for
passing that URI in *but* this is where the confusion takes a turn for
the worse.
Why does this work?
var uri = encodeURI("http://domain.com%");
decodeURI(uri);
whats the trick usage here? I mean, why does a malformed URI passed
directly to decode choke but if I simply encode it, decode won't choke
and return exactly the URI I passed in uncoded? I expect, whatever may
be passed in to decode will simply return decoded *if* possible e.g.,
example 2.
I am certain, this is most likely on purpose but am failing to
understand how, why, when, etc :/
Can someone help clear this up for me, thanks a million!