So I am trying to decode a string that was previously urlencoded with php in Node. About a month ago I had it working with:
querystring.unescape(str.replace(/\+/g, '%20'));
Then it just stopped working - not sure if it was some Node upgrade or what. After playing around it seems I can just use 'unescape()' but I am not sure it if it's foolproof yet.
unescape(str.replace(/\+/g, '%20'));
My question is what is the best way and has anyone else noticed this issue. Note that the first line works with simple strings but breaks down with odd characters - so maybe some encoding issue I am not seeing.
Here's a string:
%E6.%82%CCI-T%8C%01+A
Now go to http://www.tareeinternet.com/scripts/unescape.html and decode it. That is my original (it's an RC4 encrypted string). I want Node to return that string.
PHP | urldecode() Function The urldecode() function is an inbuilt function in PHP which is used to decode url which is encoded by encoded() function. Parameters: This function accepts single parameter $input which holds the url to be decoded. Return Value: This function returns the decoded string on success.
Another function called the urldecode() function is another inbuilt function of PHP and is implemented for decoding the URL, encoded by the urlencode() function. Decoding is the approach of reversing the non-ASCII data back to its original form. This function will accept a single string as its parameter.
The urldecode() and rawurldecode() functions are used to roll back the changes made by corresponding urlencode() and rawurlencode() functions. This basically means that all sequences which contain a percent sign followed by two hex strings will be replaced with their proper characters.
If you just use the unescape
function that's built in into Node.js, your result should be what you want.
Using Node.js 0.10.1 and running
unescape('%E6.%82%CCI-T%8C%01+A');
on the interactive shell, I get
'æ.ÌI-T\u0001+A'
as result which looks pretty much like what you would like to get.
Hope this helps :-)
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