I got garbled character with [email protected] in nodejs project

555 Views Asked by At

I am working on a nodejs project. There is company name 'ABC AEROLÍNEAS SA DE CV' in DB2. While using [email protected] to get the name, it turned into 'ABC AEROL�NEAS SA DE CV' in my nodejs.

I tried to verify it by using python with ibm_db 3.0.1 and got 'ABC AEROL\xcdNEAS SA DE CV'. I think the '\xcd' should be correct since it displays 'ABC AEROLÍNEAS SA DE CV' in python console. Furthermore, I tested it by JDBC and got the correct name too.

I don't know why nodejs's ibm_db cannot get the correct name. Could someone help to check this? Thanks.

DB DB

NodeJS NodeJS

Python Python

1

There are 1 best solutions below

7
Paul Vernon On

The hex value \xCD is an (extended) ASCII value. In UTF-8 you would need \xC3\x8D. In UTF-16 you would need \x00\xCD.

https://en.wikipedia.org/wiki/%C3%8D#Character_mappings

Do note that some Windows native programs will display invalid UTF-8 bytes as valid characters, when strictly they should be displaying or similar.

If you use a JDBC based SQL editor, you would see � (or a null value) in your string