Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
[advisories]
ignore = [
{ id = "RUSTSEC-2024-0436", reason = "`paste` - macro crate without replacement" },
{ id = "RUSTSEC-2025-0052", reason = "`async-std` - unmaintained without replacement - needs some time to replace, but async version isn't too important right now" },
]


Expand Down
2 changes: 1 addition & 1 deletion gix-url/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description = "A crate of the gitoxide project implementing parsing and serializ
authors = ["Sebastian Thiel <sebastian.thiel@icloud.com>"]
edition = "2021"
include = ["src/**/*", "LICENSE-*", "tests/baseline/**/*"]
rust-version = "1.70"
rust-version = "1.74"

[lib]
doctest = false
Expand Down
27 changes: 21 additions & 6 deletions gix-url/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ pub enum ArgumentSafety<'a> {
///
/// Additionally there is support for [deserialization](Url::from_bytes()) and [serialization](Url::to_bstring()).
///
/// # Mutability Warning
///
/// Due to the mutability of this type, it's possible that the URL serializes to something invalid
/// when fields are modified directly. URLs should always be parsed to this type from string or byte
/// parameters, but never be accepted as an instance of this type and then reconstructed, to maintain
/// validity guarantees.
///
/// # Security Warning
///
/// URLs may contain passwords and using standard [formatting](std::fmt::Display) will redact
Expand All @@ -93,13 +100,13 @@ pub struct Url {
/// The URL scheme.
pub scheme: Scheme,
/// The user to impersonate on the remote.
user: Option<String>,
pub user: Option<String>,
/// The password associated with a user.
password: Option<String>,
pub password: Option<String>,
/// The host to which to connect. Localhost is implied if `None`.
host: Option<String>,
pub host: Option<String>,
/// When serializing, use the alternative forms as it was parsed as such.
serialize_alternative_form: bool,
pub serialize_alternative_form: bool,
/// The port to use when connecting to a host. If `None`, standard ports depending on `scheme` will be used.
pub port: Option<u16>,
/// The path portion of the URL, usually the location of the git repository.
Expand Down Expand Up @@ -346,7 +353,11 @@ impl Url {
out.write_all(host.as_bytes())?;
}
(None, None) => {}
(Some(_user), None) => unreachable!("BUG: should not be possible to have a user but no host"),
(Some(_user), None) => {
return Err(std::io::Error::other(
"Invalid URL structure: user specified without host",
));
}
}
if let Some(port) = &self.port {
write!(out, ":{port}")?;
Expand All @@ -370,7 +381,11 @@ impl Url {
out.write_all(host.as_bytes())?;
}
(None, None) => {}
(Some(_user), None) => unreachable!("BUG: should not be possible to have a user but no host"),
(Some(_user), None) => {
return Err(std::io::Error::other(
"Invalid URL structure: user specified without host",
));
}
}
assert!(self.port.is_none(), "BUG: cannot serialize port in alternative form");
if self.scheme == Scheme::Ssh {
Expand Down
Loading