Fix <Source as Display>::fmt impl for Source::Sprase

Add `/` to the end of the url if it doesn't have one

Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com>
This commit is contained in:
Jiahao XU 2025-06-06 00:44:19 +10:00 committed by GitHub
parent 2d7feab356
commit 8f13d324c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,4 +1,4 @@
use std::{borrow::Cow, fmt, str::FromStr};
use std::{borrow::Cow, fmt::{Self, Write as _}, str::FromStr};
use binstalk_types::maybe_owned::MaybeOwned;
use compact_str::CompactString;
@ -128,7 +128,15 @@ impl fmt::Display for Source<'_> {
Source::Git(url) => write!(f, "git+{url}"),
Source::Path(url) => write!(f, "path+{url}"),
Source::Registry(url) => write!(f, "registry+{url}"),
Source::Sparse(url) => write!(f, "sparse+{url}"),
Source::Sparse(url) => {
let url = url.as_str();
write!(f, "sparse+{url}")?;
if (url.ends_with("/")) {
Ok(())
} else {
f.write_char('/')
}
},
}
}
}