From eb2a0066ed30607993cf30a19bb882c0440584a7 Mon Sep 17 00:00:00 2001 From: qstokkink Date: Thu, 7 Nov 2024 08:56:01 +0100 Subject: [PATCH] Fixed unhexlify with variable length UTF-8 decoding --- src/tribler/ui/src/lib/utils.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/tribler/ui/src/lib/utils.ts b/src/tribler/ui/src/lib/utils.ts index 26c1be461b..7a3f34be3b 100644 --- a/src/tribler/ui/src/lib/utils.ts +++ b/src/tribler/ui/src/lib/utils.ts @@ -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) {