mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2025-11-18 11:36:17 +00:00
Update virtual-machines.tsx
This commit is contained in:
@@ -479,14 +479,31 @@ export function VirtualMachines() {
|
|||||||
return htmlRegex.test(str)
|
return htmlRegex.test(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
const processDescription = (description: string): { html: string; isHtml: boolean; error: boolean } => {
|
const decodeRecursively = (str: string, maxIterations = 5): string => {
|
||||||
|
let decoded = str
|
||||||
|
let iteration = 0
|
||||||
|
|
||||||
|
while (iteration < maxIterations) {
|
||||||
try {
|
try {
|
||||||
let decoded: string
|
const nextDecoded = decodeURIComponent(decoded.replace(/%0A/g, "\n"))
|
||||||
try {
|
|
||||||
decoded = decodeURIComponent(description.replace(/%0A/g, "\n"))
|
// If decoding didn't change anything, we're done
|
||||||
|
if (nextDecoded === decoded) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
decoded = nextDecoded
|
||||||
|
|
||||||
|
// If there are no more encoded characters, we're done
|
||||||
|
if (!/(%[0-9A-F]{2})/i.test(decoded)) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
iteration++
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// If decodeURIComponent fails, try manual decoding of common sequences
|
// If decoding fails, try manual decoding of common sequences
|
||||||
decoded = description
|
try {
|
||||||
|
decoded = decoded
|
||||||
.replace(/%0A/g, "\n")
|
.replace(/%0A/g, "\n")
|
||||||
.replace(/%20/g, " ")
|
.replace(/%20/g, " ")
|
||||||
.replace(/%3A/g, ":")
|
.replace(/%3A/g, ":")
|
||||||
@@ -497,7 +514,35 @@ export function VirtualMachines() {
|
|||||||
.replace(/%22/g, '"')
|
.replace(/%22/g, '"')
|
||||||
.replace(/%27/g, "'")
|
.replace(/%27/g, "'")
|
||||||
.replace(/%26/g, "&")
|
.replace(/%26/g, "&")
|
||||||
|
.replace(/%23/g, "#")
|
||||||
|
.replace(/%25/g, "%")
|
||||||
|
.replace(/%2B/g, "+")
|
||||||
|
.replace(/%2C/g, ",")
|
||||||
|
.replace(/%3B/g, ";")
|
||||||
|
.replace(/%3F/g, "?")
|
||||||
|
.replace(/%40/g, "@")
|
||||||
|
.replace(/%5B/g, "[")
|
||||||
|
.replace(/%5D/g, "]")
|
||||||
|
.replace(/%7B/g, "{")
|
||||||
|
.replace(/%7D/g, "}")
|
||||||
|
.replace(/%7C/g, "|")
|
||||||
|
.replace(/%5C/g, "\\")
|
||||||
|
.replace(/%5E/g, "^")
|
||||||
|
.replace(/%60/g, "`")
|
||||||
|
break
|
||||||
|
} catch (manualError) {
|
||||||
|
// If manual decoding also fails, return what we have
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return decoded
|
||||||
|
}
|
||||||
|
|
||||||
|
const processDescription = (description: string): { html: string; isHtml: boolean; error: boolean } => {
|
||||||
|
try {
|
||||||
|
const decoded = decodeRecursively(description)
|
||||||
|
|
||||||
// Check if it contains HTML
|
// Check if it contains HTML
|
||||||
if (isHTML(decoded)) {
|
if (isHTML(decoded)) {
|
||||||
@@ -515,12 +560,8 @@ export function VirtualMachines() {
|
|||||||
|
|
||||||
const handleEditNotes = () => {
|
const handleEditNotes = () => {
|
||||||
if (vmDetails?.config?.description) {
|
if (vmDetails?.config?.description) {
|
||||||
try {
|
const decoded = decodeRecursively(vmDetails.config.description)
|
||||||
const decoded = decodeURIComponent(vmDetails.config.description.replace(/%0A/g, "\n"))
|
|
||||||
setEditedNotes(decoded)
|
setEditedNotes(decoded)
|
||||||
} catch (error) {
|
|
||||||
setEditedNotes(vmDetails.config.description)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
setIsEditingNotes(true)
|
setIsEditingNotes(true)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user