zafarkhaja / jsemver

Java implementation of the SemVer Specification
MIT License
429 stars 82 forks source link

prerelease comparison not correct #35

Closed nrbrook closed 1 year ago

nrbrook commented 7 years ago

For two versions: 1.0.0-b9 1.0.0-b10

The comparison result is not correct – the result gives b9 greater than b10.

zafarkhaja commented 7 years ago

1.0.0-b10 < 1.0.0-b9

This is the intended behavior because alphanumeric pre-release identifiers are compared lexically. Please refer to p.11 of the SemVer 2 for the comparison rules

... Precedence for two pre-release versions with the same major, minor, and patch version MUST be determined by comparing each dot separated identifier from left to right until a difference is found as follows: identifiers consisting of only digits are compared numerically and identifiers with letters or hyphens are compared lexically in ASCII sort order. ...

If you need the numbers to be compared numerically you have to make them identifiers by themselves

1.0.0-b.9 < 1.0.0-b.10