Skip to content

Commit 3a470d1

Browse files
CopilotByron
andauthored
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] <[email protected]> Co-authored-by: Byron <[email protected]>
1 parent ad1e2ed commit 3a470d1

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

deny.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
[advisories]
1111
ignore = [
1212
{ id = "RUSTSEC-2024-0436", reason = "`paste` - macro crate without replacement" },
13+
{ id = "RUSTSEC-2025-0052", reason = "`async-std` - unmaintained without replacement - needs some time to replace, but async version isn't too important right now" },
1314
]
1415

1516

gix-url/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description = "A crate of the gitoxide project implementing parsing and serializ
99
authors = ["Sebastian Thiel <[email protected]>"]
1010
edition = "2021"
1111
include = ["src/**/*", "LICENSE-*", "tests/baseline/**/*"]
12-
rust-version = "1.70"
12+
rust-version = "1.74"
1313

1414
[lib]
1515
doctest = false

gix-url/src/lib.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ pub enum ArgumentSafety<'a> {
7878
///
7979
/// Additionally there is support for [deserialization](Url::from_bytes()) and [serialization](Url::to_bstring()).
8080
///
81+
/// # Mutability Warning
82+
///
83+
/// Due to the mutability of this type, it's possible that the URL serializes to something invalid
84+
/// when fields are modified directly. URLs should always be parsed to this type from string or byte
85+
/// parameters, but never be accepted as an instance of this type and then reconstructed, to maintain
86+
/// validity guarantees.
87+
///
8188
/// # Security Warning
8289
///
8390
/// URLs may contain passwords and using standard [formatting](std::fmt::Display) will redact
@@ -93,13 +100,13 @@ pub struct Url {
93100
/// The URL scheme.
94101
pub scheme: Scheme,
95102
/// The user to impersonate on the remote.
96-
user: Option<String>,
103+
pub user: Option<String>,
97104
/// The password associated with a user.
98-
password: Option<String>,
105+
pub password: Option<String>,
99106
/// The host to which to connect. Localhost is implied if `None`.
100-
host: Option<String>,
107+
pub host: Option<String>,
101108
/// When serializing, use the alternative forms as it was parsed as such.
102-
serialize_alternative_form: bool,
109+
pub serialize_alternative_form: bool,
103110
/// The port to use when connecting to a host. If `None`, standard ports depending on `scheme` will be used.
104111
pub port: Option<u16>,
105112
/// The path portion of the URL, usually the location of the git repository.
@@ -346,7 +353,11 @@ impl Url {
346353
out.write_all(host.as_bytes())?;
347354
}
348355
(None, None) => {}
349-
(Some(_user), None) => unreachable!("BUG: should not be possible to have a user but no host"),
356+
(Some(_user), None) => {
357+
return Err(std::io::Error::other(
358+
"Invalid URL structure: user specified without host",
359+
));
360+
}
350361
}
351362
if let Some(port) = &self.port {
352363
write!(out, ":{port}")?;
@@ -370,7 +381,11 @@ impl Url {
370381
out.write_all(host.as_bytes())?;
371382
}
372383
(None, None) => {}
373-
(Some(_user), None) => unreachable!("BUG: should not be possible to have a user but no host"),
384+
(Some(_user), None) => {
385+
return Err(std::io::Error::other(
386+
"Invalid URL structure: user specified without host",
387+
));
388+
}
374389
}
375390
assert!(self.port.is_none(), "BUG: cannot serialize port in alternative form");
376391
if self.scheme == Scheme::Ssh {

0 commit comments

Comments
 (0)