From d55e2b4db4ee9b714e6fa245d25d4eb09ed08cc1 Mon Sep 17 00:00:00 2001 From: liamcottle Date: Sun, 2 Jun 2024 12:29:30 +1200 Subject: [PATCH] decode app data as utf8 string to support emojis etc in peer and node names --- public/index.html | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/public/index.html b/public/index.html index 103c744..f317cfb 100644 --- a/public/index.html +++ b/public/index.html @@ -1645,10 +1645,16 @@ } }, + decodeBase64ToUtf8String: function(base64) { + // support for decoding base64 as a utf8 string to support emojis and cyrillic characters etc + return decodeURIComponent(atob(base64).split('').map(function(c) { + return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); + }).join('')); + }, getPeerNameFromAppData: function(appData) { try { // app data should be peer name, and our server provides it base64 encoded - return atob(appData); + return this.decodeBase64ToUtf8String(appData); } catch(e){ return "Anonymous Peer"; } @@ -1656,7 +1662,7 @@ getNodeNameFromAppData: function(appData) { try { // app data should be node name, and our server provides it base64 encoded - return atob(appData); + return this.decodeBase64ToUtf8String(appData); } catch(e){ return "Anonymous Node"; }