mirror of
https://github.com/Byron/gitoxide
synced 2025-10-06 01:52:40 +02:00
feat: Make all Url fields public
This way it's easier to manipulate the URL at will. Since there is no validation, users of URLs should never take a parsed structure, but instead take the path or URL directly to parse it themselves. Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Byron <63622+Byron@users.noreply.github.com>
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
[advisories]
|
[advisories]
|
||||||
ignore = [
|
ignore = [
|
||||||
{ id = "RUSTSEC-2024-0436", reason = "`paste` - macro crate without replacement" },
|
{ 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" },
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@@ -9,7 +9,7 @@ description = "A crate of the gitoxide project implementing parsing and serializ
|
|||||||
authors = ["Sebastian Thiel <sebastian.thiel@icloud.com>"]
|
authors = ["Sebastian Thiel <sebastian.thiel@icloud.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
include = ["src/**/*", "LICENSE-*", "tests/baseline/**/*"]
|
include = ["src/**/*", "LICENSE-*", "tests/baseline/**/*"]
|
||||||
rust-version = "1.70"
|
rust-version = "1.74"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
doctest = false
|
doctest = false
|
||||||
|
@@ -78,6 +78,13 @@ pub enum ArgumentSafety<'a> {
|
|||||||
///
|
///
|
||||||
/// Additionally there is support for [deserialization](Url::from_bytes()) and [serialization](Url::to_bstring()).
|
/// 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
|
/// # Security Warning
|
||||||
///
|
///
|
||||||
/// URLs may contain passwords and using standard [formatting](std::fmt::Display) will redact
|
/// URLs may contain passwords and using standard [formatting](std::fmt::Display) will redact
|
||||||
@@ -93,13 +100,13 @@ pub struct Url {
|
|||||||
/// The URL scheme.
|
/// The URL scheme.
|
||||||
pub scheme: Scheme,
|
pub scheme: Scheme,
|
||||||
/// The user to impersonate on the remote.
|
/// The user to impersonate on the remote.
|
||||||
user: Option<String>,
|
pub user: Option<String>,
|
||||||
/// The password associated with a user.
|
/// The password associated with a user.
|
||||||
password: Option<String>,
|
pub password: Option<String>,
|
||||||
/// The host to which to connect. Localhost is implied if `None`.
|
/// 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.
|
/// 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.
|
/// The port to use when connecting to a host. If `None`, standard ports depending on `scheme` will be used.
|
||||||
pub port: Option<u16>,
|
pub port: Option<u16>,
|
||||||
/// The path portion of the URL, usually the location of the git repository.
|
/// The path portion of the URL, usually the location of the git repository.
|
||||||
@@ -346,7 +353,11 @@ impl Url {
|
|||||||
out.write_all(host.as_bytes())?;
|
out.write_all(host.as_bytes())?;
|
||||||
}
|
}
|
||||||
(None, None) => {}
|
(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 {
|
if let Some(port) = &self.port {
|
||||||
write!(out, ":{port}")?;
|
write!(out, ":{port}")?;
|
||||||
@@ -370,7 +381,11 @@ impl Url {
|
|||||||
out.write_all(host.as_bytes())?;
|
out.write_all(host.as_bytes())?;
|
||||||
}
|
}
|
||||||
(None, None) => {}
|
(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");
|
assert!(self.port.is_none(), "BUG: cannot serialize port in alternative form");
|
||||||
if self.scheme == Scheme::Ssh {
|
if self.scheme == Scheme::Ssh {
|
||||||
|
Reference in New Issue
Block a user