Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions changelog.d/+requirement-series-ceiling.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Compatible-release, caret, and tilde requirements exclude a pre-release of the next series. `1.3.0rc1` is outside `~=1.2.0` and `~1.2.3`, and `2.0.0rc1` is outside `^1.2.0`.
20 changes: 17 additions & 3 deletions src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ fn matches_compatible_release(version: &str, floor: &str) -> bool {
return true;
}
let ceiling = series_ceiling(&components, components.len() - 2);
cmp_version(version, &ceiling) == Ordering::Less
below_series_ceiling(version, &ceiling)
}

/// `^X.Y.Z` allows anything up to the next change of the left-most non-zero
Expand All @@ -430,7 +430,7 @@ fn matches_caret(version: &str, floor: &str) -> bool {
.position(|component| *component != 0)
.unwrap_or(components.len() - 1);
let ceiling = series_ceiling(&components, significant);
cmp_version(version, &ceiling) == Ordering::Less
below_series_ceiling(version, &ceiling)
}

/// `~X.Y.Z` and `~X.Y` allow patch-level changes, `~X` minor-level ones.
Expand All @@ -444,7 +444,7 @@ fn matches_tilde(version: &str, floor: &str) -> bool {
}
let index = if components.len() >= 2 { 1 } else { 0 };
let ceiling = series_ceiling(&components, index);
cmp_version(version, &ceiling) == Ordering::Less
below_series_ceiling(version, &ceiling)
}

#[cfg(test)]
Expand Down Expand Up @@ -494,6 +494,20 @@ mod ecosystem_operator_tests {
assert!(matches_req("1.2.3rc1", "^1.2.0"));
assert!(matches_req("1.2.3", "~=1.2.0"));
}

#[test]
fn a_prerelease_of_the_next_series_is_outside_the_bound() {
// `cmp_version` orders `1.3.0rc1` before `1.3`. A series ceiling of
// `1.3` still excludes that pre-release: it is the next series, not
// a member of `1.2`.
assert!(!matches_req("1.3.0rc1", "~=1.2.0"));
assert!(!matches_req("2.0.0rc1", "^1.2.0"));
assert!(!matches_req("1.3.0rc1", "~1.2.3"));
assert!(matches_req("1.3.0rc1", "^1.2.0"));
assert!(matches_req("1.2.9rc1", "~=1.2.0"));
assert!(matches_req("1.2.9rc1", "^1.2.0"));
assert!(matches_req("1.2.9rc1", "~1.2.3"));
}
}

#[cfg(test)]
Expand Down
Loading