semver icon indicating copy to clipboard operation
semver copied to clipboard

VersionParser->normalize() returns invalid versions

Open grasmash opened this issue 3 years ago • 3 comments

I find that running $version_parser->normalize('1.30.1'); will return 1.30.1.0. That's not valid SemVer. It stems from this: https://github.com/composer/semver/blob/3953f23262f2bff1919fc82183ad9acb13ff62c9/src/VersionParser.php#L138

I suspect that I'm missing something, because this seems like too much of a bug for me to have been the first one to have noticed it. Am I missing something?

grasmash avatar May 06 '22 15:05 grasmash

Well, composer supports 4 segments in the version since day one. Reducing that to 3 segments only would be a huge risk for the ecosystem.

The goal of normalizing versions to always have the same number of segments is because PHP's version_compare does not handle properly comparing versions with different number of segments.

stof avatar May 06 '22 15:05 stof

Ok. That makes sense, though it's interesting that it does not in fact conform to the SemVer standard. Is that documented?

grasmash avatar May 06 '22 15:05 grasmash

Probably not. Normalize output is used as an internal representation and almost never shown to users.

Seldaek avatar May 06 '22 19:05 Seldaek