diff --git a/src/bin/proxmox-backup-manager.rs b/src/bin/proxmox-backup-manager.rs index 219476fc..a763d6d6 100644 --- a/src/bin/proxmox-backup-manager.rs +++ b/src/bin/proxmox-backup-manager.rs @@ -245,7 +245,7 @@ async fn task_stop(param: Value) -> Result { let mut client = connect()?; - let path = format!("api2/json/nodes/localhost/tasks/{}", upid_str); + let path = format!("api2/json/nodes/localhost/tasks/{}", tools::percent_encode_component(upid_str)); let _ = client.delete(&path, None).await?; Ok(Value::Null) diff --git a/src/bin/proxmox_backup_client/task.rs b/src/bin/proxmox_backup_client/task.rs index 29b2cc00..6f567f22 100644 --- a/src/bin/proxmox_backup_client/task.rs +++ b/src/bin/proxmox_backup_client/task.rs @@ -124,7 +124,7 @@ async fn task_stop(param: Value) -> Result { let mut client = connect(&repo)?; - let path = format!("api2/json/nodes/localhost/tasks/{}", upid_str); + let path = format!("api2/json/nodes/localhost/tasks/{}", tools::percent_encode_component(upid_str)); let _ = client.delete(&path, None).await?; Ok(Value::Null) diff --git a/src/client/task_log.rs b/src/client/task_log.rs index 7f16d84d..2e2e4d74 100644 --- a/src/client/task_log.rs +++ b/src/client/task_log.rs @@ -2,6 +2,7 @@ use anyhow::{bail, Error}; use serde_json::json; use super::HttpClient; +use crate::tools; pub async fn display_task_log( client: HttpClient, @@ -9,7 +10,7 @@ pub async fn display_task_log( strip_date: bool, ) -> Result<(), Error> { - let path = format!("api2/json/nodes/localhost/tasks/{}/log", upid_str); + let path = format!("api2/json/nodes/localhost/tasks/{}/log", tools::percent_encode_component(upid_str)); let mut start = 1; let limit = 500; diff --git a/src/tools.rs b/src/tools.rs index a9b3378d..08f9d22f 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -12,7 +12,7 @@ use std::path::Path; use anyhow::{bail, format_err, Error}; use serde_json::Value; use openssl::hash::{hash, DigestBytes, MessageDigest}; -use percent_encoding::AsciiSet; +use percent_encoding::{utf8_percent_encode, AsciiSet}; pub use proxmox::tools::fd::Fd; @@ -289,6 +289,11 @@ pub fn extract_cookie(cookie: &str, cookie_name: &str) -> Option { None } +/// percent encode a url component +pub fn percent_encode_component(comp: &str) -> String { + utf8_percent_encode(comp, percent_encoding::NON_ALPHANUMERIC).to_string() +} + pub fn join(data: &Vec, sep: char) -> String { let mut list = String::new();