Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect precedence for inexact match check #739

Merged
merged 1 commit into from
Dec 20, 2024
Merged
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
41 changes: 38 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,9 @@ impl Krate {
Source::Sparse(surl) | Source::Registry(surl) | Source::Git { url: surl, .. } => surl,
};

kurl.host() == url.host() && (exact && kurl.path() == url.path())
|| (!exact && kurl.path().starts_with(url.path()))
kurl.host() == url.host()
&& ((exact && kurl.path() == url.path())
|| (!exact && kurl.path().starts_with(url.path())))
}

#[inline]
Expand Down Expand Up @@ -614,7 +615,7 @@ pub fn krates_with_index(

#[cfg(test)]
mod test {
use super::Source;
use super::{Krate, PathBuf, Source, Url};

#[test]
fn parses_sources() {
Expand Down Expand Up @@ -675,4 +676,38 @@ mod test {
super::CRATES_IO_SPARSE_DIR
);
}

#[test]
fn inexact_match_fails_for_different_hosts() {
let krate = Krate {
source: Some(
Source::from_metadata(
"git+ssh://git@repo1.test.org/path/test.git".to_owned(),
&PathBuf::new(),
)
.unwrap(),
),
..Krate::default()
};
let url = Url::parse("ssh://git@repo2.test.org:8000").unwrap();

assert!(!krate.matches_url(&url, false));
}

#[test]
fn inexact_match_passes_for_same_hosts() {
let krate = Krate {
source: Some(
Source::from_metadata(
"git+ssh://git@repo1.test.org/path/test.git".to_owned(),
&PathBuf::new(),
)
.unwrap(),
),
..Krate::default()
};
let url = Url::parse("ssh://git@repo1.test.org:8000").unwrap();

assert!(krate.matches_url(&url, false));
}
}