NodeJS Express encodes a URL - how to decode

I use NodeJS with Express, and when I use foreign characters in the URL, they automatically get the encoding.

How to decode it back to the original line?

Before calling NodeJS, I remove the characters.

So the line: ΧΧ•Χ‘ΧžΧ”

Becomes %u05D0%u05D5%u05D1%u05DE%u05D4

Now the whole URL looks like this: http://localhost:32323/?query=%u05D0%u05D5%u05D1%u05DE%u05D4

Now in my NodeJS I get the escape string %u05D0%u05D5%u05D1%u05DE%u05D4 .

This is the corresponding code:

 var url_parts = url.parse(req.url, true); var params = url_parts.query; var query = params.query; // '%u05D0%u05D5%u05D1%u05DE%u05D4' 

I tried url and querystring , but nothing seems suitable to me.

 querystring.unescape(query); // still '%u05D0%u05D5%u05D1%u05DE%u05D4' 
+6
source share
2 answers

Update 16/03/18

escape and unescape are deprecated .

Using:
encodeURIComponent('ΧΧ•Χ‘ΧžΧ”') // %D7%90%D7%95%D7%91%D7%9E%D7%94
decodeURIComponent('%D7%90%D7%95%D7%91%D7%9E%D7%94') // ΧΧ•Χ‘ΧžΧ”

Old answer

unescape('%u05D0%u05D5%u05D1%u05DE%u05D4') gives "ΧΧ•Χ‘ΧžΧ”"

Try:

var querystring = unescape(query);

+10
source

You should use decodeURI() and encodeURI() to encode / decode URLs with foreign characters.

Using:

 var query = 'http://google.com'; query = encodeURI(query); query = decodeURI(query); // http://google.com 

Link to MDN:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURI

+12
source

All Articles