From b32b68548182c69387dcd806e5d1393f33aebf92 Mon Sep 17 00:00:00 2001 From: Lzzzt <101313294+Lzzzzzt@users.noreply.github.com> Date: Fri, 26 Jul 2024 15:24:58 +0800 Subject: [PATCH] fix: fix url encode/decode bug (#628) Signed-off-by: Lzzzt --- Cargo.lock | 1 + dragonfly-client-backend/Cargo.toml | 1 + dragonfly-client-backend/src/object_storage.rs | 8 +++++--- dragonfly-client/src/bin/dfget/main.rs | 4 ++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 490a2935..e2017cb1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1197,6 +1197,7 @@ dependencies = [ "httpmock", "libloading", "opendal", + "percent-encoding", "reqwest", "rustls", "rustls-pki-types", diff --git a/dragonfly-client-backend/Cargo.toml b/dragonfly-client-backend/Cargo.toml index d559acee..4a03397e 100644 --- a/dragonfly-client-backend/Cargo.toml +++ b/dragonfly-client-backend/Cargo.toml @@ -22,6 +22,7 @@ tonic.workspace = true url.workspace = true tracing.workspace = true opendal.workspace = true +percent-encoding.workspace = true futures = "0.3.28" libloading = "0.8.4" diff --git a/dragonfly-client-backend/src/object_storage.rs b/dragonfly-client-backend/src/object_storage.rs index fb4126b3..bfd6b1ad 100644 --- a/dragonfly-client-backend/src/object_storage.rs +++ b/dragonfly-client-backend/src/object_storage.rs @@ -18,6 +18,7 @@ use dragonfly_api::common; use dragonfly_client_core::error::BackendError; use dragonfly_client_core::{Error as ClientError, Result as ClientResult}; use opendal::{raw::HttpClient, Metakey, Operator}; +use percent_encoding::percent_decode_str; use std::fmt; use std::result::Result; use std::str::FromStr; @@ -136,14 +137,15 @@ impl TryFrom for ParsedURL { let key = url .path() .strip_prefix('/') - .ok_or_else(|| ClientError::InvalidURI(url.to_string()))? - .to_string(); + .ok_or_else(|| ClientError::InvalidURI(url.to_string()))?; + // Decode the key. + let decoded_key = percent_decode_str(key).decode_utf8_lossy().to_string(); Ok(Self { url, scheme, bucket, - key, + key: decoded_key, }) } } diff --git a/dragonfly-client/src/bin/dfget/main.rs b/dragonfly-client/src/bin/dfget/main.rs index ac9a0c49..13e6ea11 100644 --- a/dragonfly-client/src/bin/dfget/main.rs +++ b/dragonfly-client/src/bin/dfget/main.rs @@ -762,7 +762,7 @@ async fn download( } } - progress_bar.finish_with_message(format!("{} downloaded", download_path)); + progress_bar.finish(); Ok(()) } @@ -813,7 +813,7 @@ fn make_output_by_entry(url: Url, output: &Path, entry: DirEntry) -> Result