Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major version constraint circumvented by prerelease versions #73

Open
mattolenik opened this issue Sep 28, 2021 · 0 comments
Open

Major version constraint circumvented by prerelease versions #73

mattolenik opened this issue Sep 28, 2021 · 0 comments

Comments

@mattolenik
Copy link

I'm trying to implement a range check that allows any major or minor version change, but never a major change. So that anything starting with 1 but never anything starting with 2 or above.

I tried expressing that as >= 1.x, >= 1.x < 2.x, >= 1.x < 2.x.x, and >= 1.x < 2.0.0, but found that it will allow 2.x prereleases, e.g. 2.0.0-v2-5.

package main

import (
	"fmt"
	"github.com/blang/semver/v4"
)

func main() {
	v, _ := semver.Parse("2.0.0-v2-5")
	r, _ := semver.ParseRange(">= 1.x")
	fmt.Println(r(v))
	r, _ = semver.ParseRange(">= 1.x < 2.x")
	fmt.Println(r(v))
	r, _ = semver.ParseRange(">= 1.x < 2.x.x")
	fmt.Println(r(v))
	r, _ = semver.ParseRange(">= 1.x < 2.0.0")
	fmt.Println(r(v))
}

This prints true four times. I know that 2.0.0-v2-5 is "less than" 2.0.0 because it is a prerelease, but this seems to be making it caught by 1.x as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant