unescape () function is to unencode URL-encoded strings. For example, the expression
returns the string "It's hard to read!". The companion to the
unescape ()function is the
escape ()function, which does the opposite: it URL-encodes unencoded strings. Together, these functions provide a framework for manipulating search strings that commonly follow form-generated URLs.
Look again at the
unescape () example given in the preceding paragraph. You will notice that the substring "%20" is the encoded equivalent of the space character. Although some browsers may encode the space character with "%20", the more prevalent encoding method for spaces is to replace them with "+" (plus) characters. (Next time you perform a multi-word search on Alta VistaTM, for example, take a look at the location bar and you will see what I mean.)
unescape () function is obligated to give the same results for
as it does for
Unfortunately, Netscape's current implementation of
unescape ()does not live up to this standard. Instead, the expression with the pluses returns an incorrect result: "It's+hard+to+read!" Based on what I have observed from the beta releases, it looks like this problem will persist in Netscape 4.
A possible work-around is to use an alternate function,
myunescape (), which I have written to overcome the shortcomings of the original
myunescape () function works by converting all occurrences of "+" in the input string to "%20". The resulting string is then handed over to the original
unescape () function for processing, and the correct result is returned.
A laboratory is provided below to help you experiment with the various effects of the
unescape (), and
myunescape () functions. Just for fun, try entering the string "It%27s+hard+to+read%21" and see which unescape function does the job right!
June 7, 1997