[pbs-devel] [PATCH proxmox-backup 16/23] ui: utils: make parseMaintenanceMode more robust

Hannes Laimer h.laimer at proxmox.com
Fri Sep 15 08:54:50 CEST 2023


Signed-off-by: Hannes Laimer <h.laimer at proxmox.com>
---
 www/Utils.js | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/www/Utils.js b/www/Utils.js
index 56b1de30..c84227ca 100644
--- a/www/Utils.js
+++ b/www/Utils.js
@@ -662,14 +662,18 @@ Ext.define('PBS.Utils', {
 	return `${icon} ${value}`;
     },
 
-    // FIXME: this "parser" is brittle and relies on the order the arguments will appear in
     parseMaintenanceMode: function(mode) {
-	let [type, message] = mode.split(/,(.+)/);
-	type = type.split("=").pop();
-	message = message ? message.split("=")[1]
-	    .replace(/^"(.*)"$/, '$1')
-	    .replaceAll('\\"', '"') : null;
-	return [type, message];
+	if (!mode) {
+	    return [null, null];
+	}
+	return mode.split(',').reduce(([m, msg], pair) => {
+	    const [key, value] = pair.split('=');
+	    if (key === 'message') {
+		return [m, value.replace(/^"(.*)"$/, '$1').replace(/\\"/g, '"')];
+	    } else {
+		return [value ?? key, msg];
+	    }
+	}, [null, null]);
     },
 
     renderMaintenance: function(mode, activeTasks) {
-- 
2.39.2






More information about the pbs-devel mailing list