mirror of
https://github.com/storytold/craft-libs.git
synced 2026-12-01 02:36:54 +01:00
craft-xtask: pins writes a git URL's port as its number
Cargo writes the port of an http or https git URL as a number, so https://host:0443/r has the default port and its source is https://host/r. git_source and check_commits kept :0443, so a valid pin failed and check_commits could miss that repository's packages. A port of digits is now written as its number before the default port is left out.
This commit is contained in:
1 parent
f5c2f1870b
commit
26bd1410ae
2 files changed
+22
-9
No files matched your search
@@ -201,8 +201,8 @@ Some("pdf-deps") => {
|
||||
gives the source Cargo writes for a git dependency pinned to a full commit hash, and `CRATES_IO` the
|
||||
source for crates.io. `git_source` and `check_commits` write a git URL as Cargo does: the `.` and
|
||||
`..` segments of the path resolved (`https://github.com/o/./r` becomes `https://github.com/o/r`),
|
||||
and for `http` and `https` the scheme and host in lowercase, without the default port
|
||||
(`https://github.com:443/o/r` becomes `https://github.com/o/r`).
|
||||
and for `http` and `https` the scheme and host in lowercase, a port written as its number, and
|
||||
without the default port (`https://github.com:0443/o/r` becomes `https://github.com/o/r`).
|
||||
- `FeatureRule::Contains` requires the listed features and allows others. `FeatureRule::Exactly`
|
||||
allows the listed features only. Both read the package's node in `resolve.nodes`.
|
||||
- `Scope::Active` rejects a forbidden package that has a resolved node, development dependencies
|
||||
|
||||
@@ -62,8 +62,9 @@ pub fn git_source(url: &str, rev: &str) -> String {
|
||||
}
|
||||
|
||||
/// `url` as Cargo writes it in a `source`: the scheme in lowercase, the `.` and `..` segments of the
|
||||
/// path resolved, and, for `http` and `https`, the host in lowercase, an empty port or the scheme's
|
||||
/// default port (80 or 443) left out, and `/` for an empty path. Other URLs keep their authority as
|
||||
/// path resolved, and, for `http` and `https`, the host in lowercase, a port of digits written as its
|
||||
/// number, an empty port or the scheme's default port (80 or 443) left out, and `/` for an empty
|
||||
/// path. Other URLs keep their authority as
|
||||
/// written.
|
||||
fn cargo_url(url: &str) -> String {
|
||||
let Some((scheme, rest)) = url.split_once("://") else { return url.to_owned() };
|
||||
@@ -71,9 +72,9 @@ fn cargo_url(url: &str) -> String {
|
||||
let (authority, tail) = rest.split_at_checked(rest.find(['/', '?', '#']).unwrap_or(rest.len())).unwrap_or((rest, ""));
|
||||
let (path, query) = tail.split_at_checked(tail.find(['?', '#']).unwrap_or(tail.len())).unwrap_or((tail, ""));
|
||||
let path = if path.is_empty() { String::new() } else { resolve_dot_segments(path) };
|
||||
let default_port = match scheme.as_str() {
|
||||
"http" => "80",
|
||||
"https" => "443",
|
||||
let default_port: u16 = match scheme.as_str() {
|
||||
"http" => 80,
|
||||
"https" => 443,
|
||||
_ => return format!("{scheme}://{authority}{path}{query}"),
|
||||
};
|
||||
let (user, host_port) = match authority.rsplit_once('@') {
|
||||
@@ -91,9 +92,14 @@ fn cargo_url(url: &str) -> String {
|
||||
out.push('@');
|
||||
}
|
||||
out.push_str(&host.to_ascii_lowercase());
|
||||
if let Some(port) = port.filter(|port| !port.is_empty() && *port != default_port) {
|
||||
// A port of digits is written as its number, so `0443` is the default port 443.
|
||||
let port = port.filter(|port| !port.is_empty()).map(|port| match port.parse::<u16>() {
|
||||
Ok(number) if port.bytes().all(|b| b.is_ascii_digit()) => (number != default_port).then(|| number.to_string()),
|
||||
_ => Some(port.to_owned()),
|
||||
});
|
||||
if let Some(port) = port.flatten() {
|
||||
out.push(':');
|
||||
out.push_str(port);
|
||||
out.push_str(&port);
|
||||
}
|
||||
if path.is_empty() {
|
||||
out.push('/');
|
||||
@@ -955,6 +961,13 @@ mod tests {
|
||||
assert_eq!(git_source("ssh://git@Host:22/r", "abc"), "git+ssh://git@Host:22/r?rev=abc#abc");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn git_sources_write_a_port_as_its_number() {
|
||||
assert_eq!(git_source("https://host:0443/r", "abc"), "git+https://host/r?rev=abc#abc");
|
||||
assert_eq!(git_source("http://host:080/r", "abc"), "git+http://host/r?rev=abc#abc");
|
||||
assert_eq!(git_source("https://host:08443/r", "abc"), "git+https://host:8443/r?rev=abc#abc");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn git_sources_resolve_dot_segments_as_cargo_does() {
|
||||
assert_eq!(git_source("https://github.com/o/./r", "abc"), "git+https://github.com/o/r?rev=abc#abc");
|
||||
|
||||
Reference in new issue
Block a user