Merge pull request #369 from junderw/hex2utf8

Decode hex into utf8 instead of ascii
This commit is contained in:
wiz 2021-03-03 21:37:46 +09:00 committed by GitHub
commit 0ba6d651c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,11 +15,11 @@ export class Hex2asciiPipe implements PipeTransform {
if (!hex) {
return '';
}
let str = '';
let bytes: number[] = [];
for (let i = 0; i < hex.length; i += 2) {
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
bytes.push(parseInt(hex.substr(i, 2), 16));
}
return str;
return new TextDecoder('utf8').decode(Uint8Array.from(bytes));
}
}