Skip to content

Commit d963b26

Browse files
authored
Fixed unhexlify with variable length UTF-8 decoding (#8250)
2 parents 91818e5 + eb2a006 commit d963b26

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

Diff for: src/tribler/ui/src/lib/utils.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,8 @@ export function capitalize(name: string) {
3131
}
3232

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

4138
export function getFilesFromMetainfo(metainfo: string) {

0 commit comments

Comments
 (0)