Skip to content

Commit

Permalink
Fixed unhexlify with variable length UTF-8 decoding (#8250)
Browse files Browse the repository at this point in the history
  • Loading branch information
qstokkink authored Nov 7, 2024
2 parents 91818e5 + eb2a006 commit d963b26
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/tribler/ui/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ export function capitalize(name: string) {
}

export function unhexlify(input: string) {
var result = '';
for (var i = 0, l = input.length; i < l; i += 2) {
result += String.fromCharCode(parseInt(input.slice(i, i + 2), 16));
}
return result;
// Solution by SuperStormer @ https://stackoverflow.com/a/76241398
return new TextDecoder().decode(new Uint8Array([...input.matchAll(/[0-9a-f]{2}/g)].map(a => parseInt(a[0], 16))));
};

export function getFilesFromMetainfo(metainfo: string) {
Expand Down

0 comments on commit d963b26

Please sign in to comment.