You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by pe...@apache.org on 2024/03/14 13:52:17 UTC
(cloudstack) 01/01: UI: Fix Userdata registration from UI
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 <pe...@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))))