From 71ccad27c59d567a5d0aa40b1308153ef3ea5461 Mon Sep 17 00:00:00 2001 From: Bojan Galic Date: Tue, 17 Dec 2024 11:48:31 +0100 Subject: [PATCH] FIX: Git command supports commit names that contains / --- src/server/api/routes.rs | 12 ++++-------- tests/common/mod.rs | 3 +++ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/server/api/routes.rs b/src/server/api/routes.rs index a48bf55..5a37704 100644 --- a/src/server/api/routes.rs +++ b/src/server/api/routes.rs @@ -340,11 +340,7 @@ struct Info { /// Return the content in the stelae archive in the `{namespace}/{name}` /// repo at the `commitish` commit at the `remainder` path. /// Return 404 if any are not found or there are any errors. -#[route( - "/{namespace}/{name}/{commitish}{remainder:/+([^{}]*?)?/*}", - method = "GET", - method = "HEAD" -)] +#[route("/{namespace}/{name}", method = "GET", method = "HEAD")] #[tracing::instrument(name = "Retrieving a Git blob", skip(path, data, info))] #[expect( clippy::future_not_send, @@ -355,10 +351,10 @@ async fn get_blob( info: web::Query, data: web::Data, ) -> impl Responder { - let (namespace, name /* , commitish, remainder*/) = path.into_inner(); + let (namespace, name) = path.into_inner(); let info_struct: Info = info.into_inner(); let commitish = info_struct.commitish; - let remainder = info_struct.remainder.unwrap_or_else(|| "".to_string()); + let remainder = info_struct.remainder.unwrap_or_default(); let archive_path = &data.archive_path; let blob = Repo::find_blob(archive_path, &namespace, &name, &remainder, &commitish); let blob_path = clean_path(&remainder); @@ -370,7 +366,7 @@ async fn get_blob( } /// A centralised place to match potentially unsafe internal errors to safe user-facing error responses -#[allow(clippy::wildcard_enum_match_arm)] +#[expect(clippy::wildcard_enum_match_arm, reason = "Allows _ for enum matching")] #[tracing::instrument(name = "Error with Git blob request", skip(error, namespace, name))] fn blob_error_response(error: &anyhow::Error, namespace: &str, name: &str) -> HttpResponse { tracing::error!("{error}",); diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 34b113b..a09bd71 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -44,6 +44,9 @@ impl Global for TestAppState { fn db(&self) -> &db::DatabaseConnection { unimplemented!() } + fn archive_path(&self) -> &PathBuf { + unimplemented!() + } } pub async fn initialize_app(