This is an automated email from the ASF dual-hosted git repository. pearl11594 pushed a commit to branch fix-userdata-encoding in repository https://gitbox.apache.org/repos/asf/cloudstack.git
commit 0f677072701f8e6da8a66e708bb7bb25ce526d8e Author: Pearl Dsilva <pearl1...@gmail.com> AuthorDate: Thu Mar 14 09:52:01 2024 -0400 UI: Fix Userdata registration from UI --- ui/src/utils/plugins.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ui/src/utils/plugins.js b/ui/src/utils/plugins.js index be6276dbd0c..6aee71b5178 100644 --- a/ui/src/utils/plugins.js +++ b/ui/src/utils/plugins.js @@ -482,6 +482,15 @@ export const fileSizeUtilPlugin = { } } +function isBase64 (str) { + try { + const decoded = new TextDecoder().decode(Uint8Array.from(atob(str), c => c.charCodeAt(0))) + return btoa(decoded) === str + } catch (err) { + return false + } +} + export const genericUtilPlugin = { install (app) { app.config.globalProperties.$isValidUuid = function (uuid) { @@ -490,8 +499,7 @@ export const genericUtilPlugin = { } app.config.globalProperties.$toBase64AndURIEncoded = function (text) { - const base64regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/ - if (base64regex.test(text)) { + if (isBase64(text)) { return text } return encodeURIComponent(btoa(unescape(encodeURIComponent(text))))