[pbs-devel] [RFC PATCH widget-toolkit 1/1] Utils: percent-decode the task status

Dominik Csapak d.csapak at proxmox.com
Fri Oct 15 10:07:29 CEST 2021


we percent-encode the taskstatus in case of an error, so that we do not
have control characters (especially newlines) in the task log

so on showing, we decode that again

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/Utils.js             | 12 +++++++++++-
 src/panel/LogView.js     |  6 ++++++
 src/window/TaskViewer.js |  2 +-
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/src/Utils.js b/src/Utils.js
index c52bef2..e18a403 100644
--- a/src/Utils.js
+++ b/src/Utils.js
@@ -785,11 +785,21 @@ utilities: {
 	return 'error';
     },
 
+    percent_decode_ctrl_chars: function(status) {
+	return status.replaceAll(/%([0-9a-f]{2})/ig, (match, val) => {
+	    let value = parseInt(val, 16);
+	    if (value < 32 || value === 127) { // 0x00-0x1F && 0x7F (DEL)
+		return String.fromCharCode(value);
+	    }
+	    return match;
+	});
+    },
+
     format_task_status: function(status) {
 	let parsed = Proxmox.Utils.parse_task_status(status);
 	switch (parsed) {
 	    case 'unknown': return Proxmox.Utils.unknownText;
-	    case 'error': return Proxmox.Utils.errorText + ': ' + status;
+	    case 'error': return Proxmox.Utils.errorText + ': ' + Proxmox.Utils.percent_decode_ctrl_chars(status);
 	    case 'warning': return status.replace('WARNINGS', Proxmox.Utils.warningsText);
 	    case 'ok': // fall-through
 	    default: return status;
diff --git a/src/panel/LogView.js b/src/panel/LogView.js
index 1772737..4558772 100644
--- a/src/panel/LogView.js
+++ b/src/panel/LogView.js
@@ -97,6 +97,12 @@ Ext.define('Proxmox.panel.LogView', {
 			lines[line.n - 1] = Ext.htmlEncode(line.t);
 		    });
 
+		    // if last line contains a task error
+		    let last_line = lines[lines.length - 1];
+		    if (last_line.indexOf('TASK ERROR') !== -1) {
+			lines[lines.length - 1] = Proxmox.Utils.percent_decode_ctrl_chars(last_line);
+		    }
+
 		    lines.length = total;
 		    me.updateView(lines.join('<br>'), first - 1, total);
 		    me.running = false;
diff --git a/src/window/TaskViewer.js b/src/window/TaskViewer.js
index 996a41b..5444842 100644
--- a/src/window/TaskViewer.js
+++ b/src/window/TaskViewer.js
@@ -113,7 +113,7 @@ Ext.define('Proxmox.window.TaskViewer', {
 		    }
 		    let es = statgrid.getObjectValue('exitstatus');
 		    if (es) {
-			return value + ': ' + es;
+			return value + ': ' + Proxmox.Utils.percent_decode_ctrl_chars(es);
 		    }
 		    return 'unknown';
 		},
-- 
2.30.2






More information about the pbs-devel mailing list