NodeJS decodeURIComponent not working properly

nanndoj picture nanndoj · Feb 7, 2014 · Viewed 21.2k times · Source

When I tryed to decode the string below in nodeJS using decodeURLCompnent:

var decoded = decodeURI('Ulysses%20Guimar%C3%A3es%20-%20lado%20par');
console.log(decoded);

I got

Ulysses Guimarães - lado par

Instead of

Avenida Ulysses Guimarães - lado par 

But when I use the same code on the client side (browser) I can get the right char 'ã'.

Is there a way to convert from ã to ã in a Node script?

Answer

alex picture alex · Feb 8, 2014

I cannot reproduce it in 0.10 or 0.11 versions of node.

You can convert first to second using new Buffer('Ulysses Guimarães - lado par', 'binary').toString('utf8'), but it's a workaround, not a solution.

Are you sure you're calling decodeURI, not unescape?