From e3203f998b153d85199a322e8b6fee72a90c32c9 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Fri, 24 Apr 2020 22:28:15 +0200 Subject: [PATCH] Remove leading / in keys; better delimiter handling --- src/api/api_server.rs | 1 + src/api/s3_list.rs | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/api/api_server.rs b/src/api/api_server.rs index f7ca156d..58ef9460 100644 --- a/src/api/api_server.rs +++ b/src/api/api_server.rs @@ -78,6 +78,7 @@ async fn handler_inner( let (bucket, key) = match path.find('/') { Some(i) => { let (bucket, key) = path.split_at(i); + let key = key.trim_start_matches('/'); (bucket, Some(key)) } None => (path, None), diff --git a/src/api/s3_list.rs b/src/api/s3_list.rs index af160ac2..35140d1e 100644 --- a/src/api/s3_list.rs +++ b/src/api/s3_list.rs @@ -55,9 +55,13 @@ pub async fn handle_list( break; } }; - let delimited_key = match relative_key.find(delimiter) { - Some(i) => relative_key.split_at(i).1, - None => &relative_key, + let delimited_key = if delimiter.len() > 0 { + match relative_key.find(delimiter) { + Some(i) => relative_key.split_at(i).0, + None => &relative_key, + } + } else { + &relative_key }; let delimited_key = delimited_key.to_string(); let new_info = match result.get(&delimited_key) {