Skip to content

Commit

Permalink
fix(spec): Require opt-in for pre-release
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Oct 17, 2023
1 parent 0ec3274 commit d318ed4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/cargo/core/package_id_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,9 @@ mod tests {

let pre = PackageId::new("pre", "1.2.3-alpha.0", sid).unwrap();
assert!(PackageIdSpec::parse("pre").unwrap().matches(pre));
assert!(PackageIdSpec::parse("pre@1").unwrap().matches(pre));
assert!(PackageIdSpec::parse("pre@1.2").unwrap().matches(pre));
assert!(PackageIdSpec::parse("pre@1.2.3").unwrap().matches(pre));
assert!(!PackageIdSpec::parse("pre@1").unwrap().matches(pre));
assert!(!PackageIdSpec::parse("pre@1.2").unwrap().matches(pre));
assert!(!PackageIdSpec::parse("pre@1.2.3").unwrap().matches(pre));
assert!(PackageIdSpec::parse("pre@1.2.3-alpha.0")
.unwrap()
.matches(pre));
Expand Down
5 changes: 5 additions & 0 deletions src/cargo/util/semver_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ impl PartialVersion {
/// Build metadata does not affect version precedence but may be necessary for uniquely
/// identifying a package.
pub fn matches(&self, version: &Version) -> bool {
if !version.pre.is_empty() && self.pre.is_none() {
// Pre-release versions must be explicitly opted into, if for no other reason than to
// give us room to figure out and define the semantics
return false;
}
self.major == version.major
&& self.minor.map(|f| f == version.minor).unwrap_or(true)
&& self.patch.map(|f| f == version.patch).unwrap_or(true)
Expand Down

0 comments on commit d318ed4

Please sign in to comment.