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

Wildcard VersionReq doesn't match if a Version have pre-release #98

Closed
onur opened this issue Nov 10, 2016 · 8 comments
Closed

Wildcard VersionReq doesn't match if a Version have pre-release #98

onur opened this issue Nov 10, 2016 · 8 comments

Comments

@onur
Copy link

onur commented Nov 10, 2016

I believe * should match any version and currently it is not matching if a Version have a pre-release. For example:

extern crate semver;

fn main() {
    let wildcard_ver = semver::VersionReq::parse("*").unwrap();
    let another_ver = semver::Version::parse("0.1.0-pre.0").unwrap();

    assert!(wildcard_ver.matches(&another_ver));  // there is no match :(
}

This issue is also affecting cargo. For example symtern only released versions with a pre-release string and using any range syntax in Cargo.toml doesn't work. Including: *, 0.1, ^0.1, 0.1.0 etc.

I tried node's semver and * is matching (satisfying) fine with 0.1.0-pre.0.

> semver.satisfies('0.1.0-pre.0', '*')
true
> semver.satisfies('0.1.0', '*')
true

Ref: onur/docs.rs#80

@steveklabnik
Copy link
Contributor

Yes, this is intended behavior. You only get prerelease versions when explicitly asking for them. This is consistent with other semver implementations, take https://semver.npmjs.com/ and try matching * vs 1.0.0-rc.1.

which then confuses me why you say

I tried node's semver and * is matching (satisfying) fine with 0.1.0-pre.0.

@isaacs, do you know what's up here?

@onur
Copy link
Author

onur commented Nov 10, 2016

Another example from semantic_version python module:

>>> from semantic_version import Spec, Version
>>> Spec('*').match(Version('0.1.0-pre.0'))
True

I think * range is only different in npm. In theory * means any and it should match any valid semver.

@steveklabnik
Copy link
Contributor

I haven't had the time to check, but IIRC Bundler also doesn't give you prerelase explicitly.

In theory * means any and it should match any valid semver.

That depends, it should match any released version, imho, and pre-releases aren't real releases.

Anyway, this library will try to be as compatible with the rest of the ecosystem as possible, but if it's not standard across the ecosystem, then we'll do what I think is right 😉

@isaacs
Copy link

isaacs commented Nov 10, 2016

Nope, it doesn't, by design.

$ semver -r '*' 1.0.0-pre

$ echo $?
1

https://github.com/npm/node-semver/#prerelease-tags

@isaacs
Copy link

isaacs commented Nov 10, 2016

Obviously I can't speak for Python's semantic_version module, though. I'm assuming it works for its purposes. Version range specifiers are much less standardized than versions themselves, but cargo and npm are mostly in sync with one another.

@onur
Copy link
Author

onur commented Nov 10, 2016

@isaacs I am wondering why all these examples are returning true:

> var semver = require('semver')
> semver.satisfies('0.1.0-pre.0', '*')
true
> semver.satisfies('0.1.0-pre.0', '0.1')
true
> semver.satisfies('0.1.0-pre.0', '^0')
true
> semver.satisfies('0.1.0-pre.0', '0')
true

I only need this kind of behavior from semver crate. semver crate is returning false for all of these.

@isaacs
Copy link

isaacs commented Nov 10, 2016

@onur Probably you're using a very outdated version of semver.

> var semver = require('./')
undefined
> semver.satisfies('0.1.0-pre.0', '*')
false
> semver.satisfies('0.1.0-pre.0', '0.1')
false
> semver.satisfies('0.1.0-pre.0', '^0')
false
> semver.satisfies('0.1.0-pre.0', '0')
false
> require('semver/package.json').version
'5.3.0'
> require('./package.json').version
'5.3.0'

onur added a commit to rust-lang/docs.rs that referenced this issue Nov 10, 2016
I believe this is a bug in semver crate but according to NPM people, and
@steveklabnik; a version like "0.1.0-pre.0" or "0.1.0-beta.0" *is not a
real version* and any version that contains a pre-release string is getting
different treatment by semver.

IMO this is utterly wrong. Docs.rs is probably the first victim of this
behavior and it will affect more in future. `*` means any and it should
match any version. It doesn't matter if a version have a pre-release string
or not. Even older versions of node's semver were matching "*" for any
version. I don't know why they changed this behavior but I am not surprised
any means "anything except a version that contains pre-release" in JS
world.

Fixes: #80
Ref: dtolnay/semver#98
@onur
Copy link
Author

onur commented Nov 10, 2016

@isaacs that figures:

> require('semver/package.json').version
'2.1.0'

TBH I don't know why this behavior is changed but old one seems more correct to me. Ranges are useless if a crate have a pre-release string. And * means any except it's not any.

Anyway I am closing this issue since semver crate is using node-semver behavior.

@onur onur closed this as completed Nov 10, 2016
hadronized pushed a commit to hadronized/docs.rs that referenced this issue Nov 30, 2016
I believe this is a bug in semver crate but according to NPM people, and
@steveklabnik; a version like "0.1.0-pre.0" or "0.1.0-beta.0" *is not a
real version* and any version that contains a pre-release string is getting
different treatment by semver.

IMO this is utterly wrong. Docs.rs is probably the first victim of this
behavior and it will affect more in future. `*` means any and it should
match any version. It doesn't matter if a version have a pre-release string
or not. Even older versions of node's semver were matching "*" for any
version. I don't know why they changed this behavior but I am not surprised
any means "anything except a version that contains pre-release" in JS
world.

Fixes: rust-lang#80
Ref: dtolnay/semver#98
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants