-
-
Notifications
You must be signed in to change notification settings - Fork 132
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
VersionReq with build metadata ignored? #107
Comments
(originally discovered through alexcrichton/cargo-vendor#21) |
(also feel free to close if this is expected) |
|
In light of that... is there any way to request a precise version through a Basically, given a |
This is not possible with the current version of the We could add a way to do this by inventing a new range operator for metadata-sensitive ranges. For example if the new operator was |
Does that mean that crates.io should disallow packages whose versions differ only by build metadata? |
Perhaps yeah, we don't seem to have many other options here |
This seems like it's misreading the spec to me. Metadata is ignored for precedence, but that does not mean it is ignored when determining equality.
It seems to me this would mean that sorting |
I believe this behavior is consistent with how build metadata is intended to work, for better or worse. https://github.com/semver/semver/blob/efcff2c838c9945f79bfd21c1df0073271bcc29c/ranges.md is pretty clear about this:
Therefore a requirement like If Cargo wants to prioritize a different one of those matching versions when resolving such a requirement, I think that would be a separate action from matching. My suggestion would be something like: use semver::{Op, Version, VersionReq};
fn main() {
let req = "=1.0.1+1.7.3";
let v = "1.0.1+1.7.5";
println!("{}", matches(req, v));
}
fn matches(req_str: &str, version_str: &str) -> bool {
let req = VersionReq::parse(req_str).unwrap();
let v = Version::parse(version_str).unwrap();
let same_patch_different_build = || {
if req.comparators.len() != 1 {
return false;
}
let cmp = &req.comparators[0];
cmp.op == Op::Exact
&& cmp.major == v.major
&& cmp.minor == Some(v.minor)
&& cmp.patch == Some(v.patch)
&& cmp.pre == v.pre
&& !req_str.ends_with(version_str)
};
req.matches(&v) && !same_patch_different_build()
} That said, this crate is now explicitly scoped as implementing Cargo's interpretation of SemVer, so if the suggestion above is not appealing or feasible for Cargo, then I would be prepared to change the behavior of matching to fit how Cargo chooses to interpret SemVer. |
This program produces surprising results (to me at least):
The last line prints
true
, but I'd expect it to print false? It looks like the+1.7.3
isn't being parsed ina
?The text was updated successfully, but these errors were encountered: