From 8691a5e048eb05a1f65455bb8d52a96b1ac6bc96 Mon Sep 17 00:00:00 2001 From: CyberMind-FR Date: Wed, 4 Feb 2026 09:40:51 +0100 Subject: [PATCH] fix(streamlit): Fix btoa crash on UTF-8 .py file upload Read all files as ArrayBuffer and use Uint8Array chunked encoding for base64, replacing btoa(text) which throws DOMException on non-ASCII characters (accents, CJK, etc). Co-Authored-By: Claude Opus 4.5 --- .../resources/view/streamlit/dashboard.js | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/package/secubox/luci-app-streamlit/htdocs/luci-static/resources/view/streamlit/dashboard.js b/package/secubox/luci-app-streamlit/htdocs/luci-static/resources/view/streamlit/dashboard.js index 2410ef4c..36706cd3 100644 --- a/package/secubox/luci-app-streamlit/htdocs/luci-static/resources/view/streamlit/dashboard.js +++ b/package/secubox/luci-app-streamlit/htdocs/luci-static/resources/view/streamlit/dashboard.js @@ -615,18 +615,12 @@ return view.extend({ var reader = new FileReader(); reader.onload = function(e) { - var content; - if (isZip) { - var binary = e.target.result; - var bytes = new Uint8Array(binary); - var chunks = []; - for (var i = 0; i < bytes.length; i += 8192) { - chunks.push(String.fromCharCode.apply(null, bytes.slice(i, i + 8192))); - } - content = btoa(chunks.join('')); - } else { - content = btoa(e.target.result); + var bytes = new Uint8Array(e.target.result); + var chunks = []; + for (var i = 0; i < bytes.length; i += 8192) { + chunks.push(String.fromCharCode.apply(null, bytes.slice(i, i + 8192))); } + var content = btoa(chunks.join('')); var uploadFn = isZip ? api.uploadZip(name, content, null) : api.uploadApp(name, content); @@ -645,11 +639,7 @@ return view.extend({ }); }; - if (isZip) { - reader.readAsArrayBuffer(file); - } else { - reader.readAsText(file); - } + reader.readAsArrayBuffer(file); }, renameApp: function(id, currentName) {