An alternative to unescape in node.js

I am using a deprecated function unescape

in one of my programs.

The protocol I am working with sends escape

d binary strings through the query string. So on their side, they do something line by line (0-9, az, AZ, '.', '-', '_' and '~' are encoded using the "% nn" format):

var source = "\x12\x34\x56\x78\x9a\xbc\xde\xf1\x23\x45\x67\x89\xab\xcd\xef\x12\x34\x56\x78\x9a";
var encoded = escape(source);
// escaped is now "%124Vx%9A%BC%DE%F1%23Eg%89%AB%CD%EF%124Vx%9A"

      

So, I am getting this string at my end and I need to decode it. decodeURIComponent

doesn't work in this case, so I rely on unescape

:

var received = "%124Vx%9A%BC%DE%F1%23Eg%89%AB%CD%EF%124Vx%9A";
var binaryString = unescape(received);

      

Since unescape

deprecated, any pointers on how I should decode these binary strings?

Note: querystring.unescape

doesn't work either ...

+3


source to share


1 answer


The function is unescape()

deprecated in JavaScript version 1.5. Use decodeURI()

or instead decodeURIComponent()

.



The function unescape()

decodes the encoded string.

0


source







All Articles