From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [RFC PATCH proxmox-backup 1/1] rest-server: tasks: percent-encode the task status line
Date: Fri, 15 Oct 2021 10:07:30 +0200 [thread overview]
Message-ID: <20211015080730.1427860-3-d.csapak@proxmox.com> (raw)
In-Reply-To: <20211015080730.1427860-1-d.csapak@proxmox.com>
we always want the status line of the task log to be a single line
(makes the parsing easier), for that purpose, percent-encode it
(we can decode it again when we need to)
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
pbs-tools/src/percent_encoding.rs | 5 +++++
proxmox-rest-server/src/worker_task.rs | 4 +++-
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/pbs-tools/src/percent_encoding.rs b/pbs-tools/src/percent_encoding.rs
index afe011e2..dae9a50d 100644
--- a/pbs-tools/src/percent_encoding.rs
+++ b/pbs-tools/src/percent_encoding.rs
@@ -20,3 +20,8 @@ pub const DEFAULT_ENCODE_SET: &AsciiSet = &percent_encoding::CONTROLS // 0..1f a
pub fn percent_encode_component(comp: &str) -> String {
utf8_percent_encode(comp, percent_encoding::NON_ALPHANUMERIC).to_string()
}
+
+/// percent encode control characters in a string
+pub fn percent_encode_control_characters(comp: &str) -> String {
+ utf8_percent_encode(comp, percent_encoding::CONTROLS).to_string()
+}
diff --git a/proxmox-rest-server/src/worker_task.rs b/proxmox-rest-server/src/worker_task.rs
index fb0dea9b..fb101b50 100644
--- a/proxmox-rest-server/src/worker_task.rs
+++ b/proxmox-rest-server/src/worker_task.rs
@@ -23,6 +23,7 @@ use proxmox_schema::upid::UPID;
use pbs_tools::task::WorkerTaskContext;
use pbs_tools::logrotate::{LogRotate, LogRotateFiles};
+use pbs_tools::percent_encoding::percent_encode_control_characters;
use crate::{CommandSocket, FileLogger, FileLogOptions};
@@ -853,7 +854,8 @@ impl WorkerTask {
/// Log task result, remove task from running list
pub fn log_result(&self, result: &Result<(), Error>) {
let state = self.create_state(result);
- self.log_message(state.result_text());
+ // percent encode it to avoid control characters (e.g. newlines in the status line)
+ self.log_message(percent_encode_control_characters(&state.result_text()));
WORKER_TASK_LIST.lock().unwrap().remove(&self.upid.task_id);
let _ = self.setup.update_active_workers(None);
--
2.30.2
prev parent reply other threads:[~2021-10-15 8:08 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 " Dominik Csapak
2021-10-15 8:07 ` [pbs-devel] [RFC PATCH widget-toolkit 1/1] Utils: percent-decode the task status Dominik Csapak
2021-10-15 8:07 ` Dominik Csapak [this message]
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-3-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal