Skip to content

Commit

Permalink
Normalize repo url
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Liu <[email protected]>
  • Loading branch information
austin362667 committed Sep 2, 2024
1 parent 5fe6435 commit e48c35a
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -316,9 +320,18 @@ fn complete_registry(opt: &PublishOpt) -> Result<Registry> {
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())
Expand Down

0 comments on commit e48c35a

Please sign in to comment.