Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed unhexlify with variable length UTF-8 decoding #8250

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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