Masterminds / semver

Work with Semantic Versions in Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

v1 - issue with major only constraint

paulcacheux opened this issue · comments

Hello !

Surprisingly the following code outputs true: https://go.dev/play/p/wZGWuivr35Q

package main

import (
	"fmt"

	"github.com/Masterminds/semver"
)

func main() {
	c, err := semver.NewConstraint("< 7")
	if err != nil {
		panic(err)
	}

	v, err := semver.NewVersion("7.0.0")
	if err != nil {
		panic(err)
	}

	fmt.Println(c.Check(v))
}

while https://go.dev/play/p/e-e-I7JDkKY outputs false

package main

import (
	"fmt"

	"github.com/Masterminds/semver"
)

func main() {
	c, err := semver.NewConstraint("< 7.0.0")
	if err != nil {
		panic(err)
	}

	v, err := semver.NewVersion("7.0.0")
	if err != nil {
		panic(err)
	}

	fmt.Println(c.Check(v))
}

is this behavior intended ? Thanks !

This behavior is intended. < 7 and < 7.0.0 are two different values. < 7 is < 7.x.x which means anything that's a 7 major version.

Also note, your example uses semver v1. The current supported version is v3.

I strongly disagree that this is this simple:

How could "< 7" ever mean "anything that's a 7 major version", it's in complete contradiction of the usual sense of "lower than"

It was the intended behavior in v1 of the semver package. v3 of the package came out more than 3 years ago. Changing this behavior required making a major version change and this was one of the things we changed. You should no longer use the v1 package.

I understand you disagree with a design decision that was made more than 6 years ago and that was changed in v3 more than 3 years ago.

Closing as the v1 release is no longer supported.