public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [RFC PATCH widget-toolkit 1/1] Utils: percent-decode the task status
Date: Fri, 15 Oct 2021 10:07:29 +0200	[thread overview]
Message-ID: <20211015080730.1427860-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20211015080730.1427860-1-d.csapak@proxmox.com>

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@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





  reply	other threads:[~2021-10-15  8:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-15  8:07 [pbs-devel] [RFC PATCH widget-toolkit/backup] percent encode the task status line Dominik Csapak
2021-10-15  8:07 ` Dominik Csapak [this message]
2021-10-15  8:07 ` [pbs-devel] [RFC PATCH proxmox-backup 1/1] rest-server: tasks: percent-encode " Dominik Csapak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211015080730.1427860-2-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal