rbarrois/python-semanticversion

NpmSpec Comparison Between Prerelease Versions is Wrong

Opened this issue ยท 6 comments

Version is 2.8.5.

>>> from semantic_version import NpmSpec, Version
>>> NpmSpec("<0.1.1-alpha.1").match(Version("0.1.1-beta.1"))
True
>>> NpmSpec("<0.1.1-alpha.1").match(Version("0.1.1-rc.1"))
True
>>> NpmSpec("<0.1.1-beta.7").match(Version("0.1.1-beta.8"))
True

They should be false.

This looks indeed like a bug; I don't understand why the current tests fail to detect it :/

Because you only test '>1.2.3-alpha.3' and '>=1.2.3-alpha.3' cases (GT and GTE). No cases for prerelease versions with LT and LTE. :)

possibly related:

>>> NpmSpec(">=2.0.1-").match(Version("2.0.1-rc1"))
False
>>> NpmSpec(">=2.0.1-0").match(Version("2.0.1-rc1"))
True

I believe >=2.0.1- should match all 2.0.1 prerelease versions of 2.0.1, but in actuality you need to add some character after the -

oh and the same issue with ~2.0.1- not matching anything

Here's another example that doesn't seem correct.

>>> from semantic_version import NpmSpec, Version
>>> NpmSpec("5.4.0-alpha.0").match(Version("5.4.0-alpha.0"))
True
>>> NpmSpec("5.4.0-alpha.0").match(Version("5.4.0"))
True  # this should be False

The same examples in semver from npm have the correct logic:

> var semver = require('semver');
> semver.satisfies('2.0.0-next.1', '2.0.0-next.1');
true
> semver.satisfies('2.0.0', '2.0.0-next.1');
false

Any news about this?
I also encountered it (with jquery-ui that selected the beta version instead of latest stable).

> NpmSpec('<1.14.0').select([Version('1.13.3'), Version('1.14.0-beta.1')])
Version('1.14.0-beta.1')