Encoding Node/Postegres SQL_ASCII

Asked

Viewed 119 times

0

I have an API on Node that connects to a Postgresql database using the "pg" module, where the database in question uses the "SQL_ASCII" encoding. I do not have the option to change the encoding of the bank because it is the same of the city hall of my city.

When I do a search in a table/field that contains special characters such as "Administração", I have the following return: "Administr\\xe7\\xe3o".

inserir a descrição da imagem aqui

From the research I’ve been doing, \xe7 is the Unicode code of the letter ç, I can even translate this string if I use Javascript methods such as decodeURIComponent("\xe7"),

inserir a descrição da imagem aqui

However, the answer I have is with TWO bars ("\\xe7"), so all the methods I tried to use didn’t work. Obviously I also tried to do the '\\xe7'.replace('\\\\\', '\\') to then try to use Code, but I was unsuccessful.

When I place this string in an HTML page (utf8), it shows as follows: "Administr\xe7\xe3o" with 1 bar, and my goal is to show the correct word.

Where am I going wrong?

1 answer

0


I think you’re confusing the encodings. %C3%A7 is encoded in URI, xe7 is the only hexadecimal of ç.

Try it this way:

const area = "Administra\\\\xe7\\\\xe3o";
console.log(area);

const area_decod = unescape(area.replace(/\\\\x/g, '%'));
console.log(area_decod);

  • It worked! Thank you so much! save me! Really I was confusing then. If it’s not too much to ask, could you explain this regex that was made? or some link where I can learn more about it. Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.