From e48c35a06e6c58c196ec63a2271218bbe2c8575a Mon Sep 17 00:00:00 2001 From: Austin Liu Date: Mon, 2 Sep 2024 17:08:33 +0800 Subject: [PATCH] Normalize repo url Signed-off-by: Austin Liu --- src/upload.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/upload.rs b/src/upload.rs index 5560a62e1..dbe4e3fb4 100644 --- a/src/upload.rs +++ b/src/upload.rs @@ -69,6 +69,10 @@ impl PublishOpt { self.non_interactive = true; } } + /// Helper function to normalize URLs by removing trailing slashes + fn normalize_url(url: &str) -> &str { + url.trim_end_matches('/') + } } /// Error type for different types of errors that can happen when uploading a @@ -316,9 +320,18 @@ fn complete_registry(opt: &PublishOpt) -> Result { let pypirc = load_pypirc(); let (registry_name, registry_url) = if let Some(repository_url) = opt.repository_url.as_deref() { - let name = match repository_url { - PublishOpt::DEFAULT_REPOSITORY_URL => Some("pypi"), - PublishOpt::TEST_REPOSITORY_URL => Some("testpypi"), + let normalized_url = PublishOpt::normalize_url(repository_url); + let name = match normalized_url { + normalized + if normalized == PublishOpt::normalize_url(PublishOpt::DEFAULT_REPOSITORY_URL) => + { + Some("pypi") + } + normalized + if normalized == PublishOpt::normalize_url(PublishOpt::TEST_REPOSITORY_URL) => + { + Some("testpypi") + } _ => None, }; (name, repository_url.to_string())