From bb26e04a55e2ef139656adf35f24bf0a43404f93 Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Thu, 21 Sep 2023 14:21:16 -0400 Subject: [PATCH] aws: s3: Properly percent-decode GstS3Url We previously only percent-decoded the first fragment. This doesn't necessarily harm anything, but for consistency we keep the structure un-encoded, and encode when converting to a string representation. Part-of: --- net/aws/src/s3url.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/net/aws/src/s3url.rs b/net/aws/src/s3url.rs index 8d174d13..7a9d031f 100644 --- a/net/aws/src/s3url.rs +++ b/net/aws/src/s3url.rs @@ -83,15 +83,21 @@ pub fn parse_s3_url(url_str: &str) -> Result { .next() .ok_or_else(|| format!("Invalid empty object/bucket '{url}'"))?; - let mut object = percent_decode(o.as_bytes()) - .decode_utf8() - .unwrap() - .to_string(); if o.is_empty() { return Err(format!("Invalid empty object/bucket '{url}'")); } - object = path.fold(object, |o, p| format!("{o}/{p}")); + let mut object = percent_decode(o.as_bytes()) + .decode_utf8() + .unwrap() + .to_string(); + + object = path.fold(object, |o, p| { + format!( + "{o}/{}", + percent_decode(p.as_bytes()).decode_utf8().unwrap() + ) + }); let mut q = url.query_pairs(); let v = q.next();