semver icon indicating copy to clipboard operation
semver copied to clipboard

Sorting with build versions: Normal version should be larger than build version

Open binwiederhier opened this issue 12 years ago • 5 comments

Hi again. Semver 2.0.0 states in bullet point 11 that "Build metadata does not figure into precedence". Furthermore it states that "Build metadata SHOULD be ignored when determining version precedence."

However, I think that build versions should be smaller than normal versions, i.e. that 0.1.0-alpha > 0.1.0-alpha+123 > 0.1.0-alpha+122. Maybe you could add a flag to allow factoring in build metadata in the sorting process, Sort::sort($versions, true)

$sorted = Sort::sort(
    "0.1.0-alpha",
    "0.1.0",
    "0.1.0-alpha+SNAPSHOT.1404162053git381bf34",
    "0.1.0-alpha+SNAPSHOT.1304162053git381bf34",
    "0.1.0-alpha+SNAPSHOT.15",
    "0.1.0+SNAPSHOT.15" 
);

OUTPUTS:

0.1.0-alpha.0
0.1.0-alpha.0+build..SNAPSHOT.15
0.1.0-alpha.0+build..SNAPSHOT.1304162053git381bf34
0.1.0-alpha.0+build..SNAPSHOT.1404162053git381bf34
0.1.0
0.1.0+build..SNAPSHOT.15

I would expect:

0.1.0-alpha.0+build..SNAPSHOT.1304162053git381bf34
0.1.0-alpha.0+build..SNAPSHOT.1404162053git381bf34
0.1.0-alpha.0+build..SNAPSHOT.15
0.1.0-alpha.0
0.1.0+build..SNAPSHOT.15
0.1.0

binwiederhier avatar Apr 18 '14 13:04 binwiederhier

To get this straight, the build data itself would then be alphabetically ordered?

naneau avatar Apr 18 '14 15:04 naneau

Yes, that's what I suggest anyway.

binwiederhier avatar Apr 18 '14 17:04 binwiederhier

SemVer 2.0 is pretty clear that "Build metadata does not figure into precedence". It also states that pre-release identifiers are ordered alphabetically. This is different from how the library functions at this point, and will have to be adressed.

naneau avatar Jun 17 '14 17:06 naneau

True. I'm just saying if it's not too much trouble. If it is or you don't want people to rely on it, feel free to close this issue.

binwiederhier avatar Jun 17 '14 19:06 binwiederhier

I get your point but it is not standards compliant. I will keep the issue open, but if it is introduced it will be separately marked in the API (and non-standard when comparing).

naneau avatar Jun 17 '14 19:06 naneau