diff --git a/ui/public/locales/en.json b/ui/public/locales/en.json
index e798a798c70..c49fef5e4fe 100644
--- a/ui/public/locales/en.json
+++ b/ui/public/locales/en.json
@@ -1110,6 +1110,7 @@
"label.ipv6.subnets": "IPv6 Subnets",
"label.ip.addresses": "IP Addresses",
"label.iqn": "Target IQN",
+"label.is.base64.encoded": "Base64 encoded",
"label.is.in.progress": "is in progress",
"label.is.shared": "Is shared",
"label.is2faenabled": "Is 2FA enabled",
diff --git a/ui/src/utils/plugins.js b/ui/src/utils/plugins.js
index acaebf45892..e358988fac9 100644
--- a/ui/src/utils/plugins.js
+++ b/ui/src/utils/plugins.js
@@ -486,6 +486,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) {
@@ -494,8 +503,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))))
diff --git a/ui/src/views/compute/RegisterUserData.vue b/ui/src/views/compute/RegisterUserData.vue
index 990e59ff277..8e6311fdf9a 100644
--- a/ui/src/views/compute/RegisterUserData.vue
+++ b/ui/src/views/compute/RegisterUserData.vue
@@ -43,6 +43,9 @@
v-model:value="form.userdata"
:placeholder="apiParams.userdata.description"/>
+
+
+
@@ -147,7 +150,9 @@ export default {
methods: {
initForm () {
this.formRef = ref()
- this.form = reactive({})
+ this.form = reactive({
+ isbase64: false
+ })
this.rules = reactive({
name: [{ required: true, message: this.$t('message.error.name') }],
userdata: [{ required: true, message: this.$t('message.error.userdata') }]
@@ -204,7 +209,7 @@ export default {
if (this.isValidValueForKey(values, 'account') && values.account.length > 0) {
params.account = values.account
}
- params.userdata = this.$toBase64AndURIEncoded(values.userdata)
+ params.userdata = values.isbase64 ? values.userdata : this.$toBase64AndURIEncoded(values.userdata)
if (values.params != null && values.params.length > 0) {
var userdataparams = values.params.join(',')