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

Checking Version Constraints is unpredictable while patch is missing in version string #178

Open
pkbhowmick opened this issue Jul 22, 2022 · 1 comment
Labels

Comments

@pkbhowmick
Copy link

When I was trying to validate version 14.1.1-debian against constraints 14.1.1-alpine, it was giving error like 14.1.1-debian is not equal to 14.1.1-alpine which is expected.

But when I was trying version 14.1-debian against constraints 14.1-alpine, it was considered as valid version which is not expected to me.

semver version: v3.1.1

For reproducing the error, I have given my go code below:

package main

import (
	"fmt"
	"github.com/Masterminds/semver/v3"
	"log"
)

func main() {
	c, err := semver.NewConstraint("14.1-alpine")
	if err != nil {
		log.Fatalln(err)
	}

	v, err := semver.NewVersion("14.1-debian")
	if err != nil {
		log.Fatalln(err)
	}

	valid, errs := c.Validate(v)
	if len(errs) > 0 {
		log.Fatalln(errs)
	}
	fmt.Println(valid)
}

Output:

 true
@mattfarina mattfarina added the bug label Aug 9, 2022
@mattfarina mattfarina added question and removed bug labels Aug 27, 2024
@mattfarina
Copy link
Member

The constraint in c, err := semver.NewConstraint("14.1-alpine") expands to 14.1.x-alpine. The x is a wildcard. In the line v, err := semver.NewVersion("14.1-debian") the version expands to 14.1.0-debian. The version fits within the constraint.

This is all because semver is 3 segments to a version and the constraint system has wildcard and ranges.

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

No branches or pull requests

2 participants