aboutsummaryrefslogtreecommitdiffstats
path: root/view/js/main.js
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2021-10-14 18:16:27 +0000
committerMario <mario@mariovavti.com>2021-10-14 18:16:27 +0000
commit9b8b85545fef4be30ee6085c4ffc7bc152d5448c (patch)
treea44fae6e8b199341d6d5aee933a3a96310cbe1a7 /view/js/main.js
parent532b479f96eea701080d5533e5f28acab9af76ba (diff)
parentc3d1474f5951558b6eb01bfcbf04f94b2e648ba5 (diff)
downloadvolse-hubzilla-9b8b85545fef4be30ee6085c4ffc7bc152d5448c.tar.gz
volse-hubzilla-9b8b85545fef4be30ee6085c4ffc7bc152d5448c.tar.bz2
volse-hubzilla-9b8b85545fef4be30ee6085c4ffc7bc152d5448c.zip
Merge branch 'dev' of https://framagit.org/hubzilla/core into dev
Diffstat (limited to 'view/js/main.js')
-rw-r--r--view/js/main.js38
1 files changed, 12 insertions, 26 deletions
diff --git a/view/js/main.js b/view/js/main.js
index 476e78056..d3f4eff9a 100644
--- a/view/js/main.js
+++ b/view/js/main.js
@@ -1457,35 +1457,21 @@ function preview_post() {
}
function bin2hex(s) {
- // Converts the binary representation of data to hex
- //
- // version: 812.316
- // discuss at: http://phpjs.org/functions/bin2hex
- // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
- // + bugfixed by: Onno Marsman
- // + bugfixed by: Linuxworld
- // * example 1: bin2hex('Kev');
- // * returns 1: '4b6576'
- // * example 2: bin2hex(String.fromCharCode(0x00));
- // * returns 2: '00'
- var v,i, f = 0, a = [];
- s += '';
- f = s.length;
-
- for (i = 0; i<f; i++) {
- a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
- }
-
- return a.join('');
+ // UTF-8 encoding to hex is supported
+ var bytes = new TextEncoder().encode(s);
+ return Array.from(
+ bytes,
+ byte => byte.toString(16).padStart(2, "0")
+ ).join("");
}
function hex2bin(hex) {
- var bytes = [], str;
-
- for(var i=0; i< hex.length-1; i+=2)
- bytes.push(parseInt(hex.substr(i, 2), 16));
-
- return String.fromCharCode.apply(String, bytes);
+ // UTF-8 decoding from hex is supported
+ var bytes = new Uint8Array(hex.length / 2);
+ for (i = 0; i !== bytes.length; i++) {
+ bytes[i] = parseInt(hex.substr(i * 2, 2), 16);
+ }
+ return new TextDecoder().decode(bytes);
}
function groupChangeMember(gid, cid, sec_token) {