[pbs-devel] [RFC PATCH proxmox-backup 1/1] rest-server: tasks: percent-encode the task status line

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


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





More information about the pbs-devel mailing list