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

Constraint check fails for .0 patch prereleases #78

Open
johanneskra opened this issue Feb 23, 2023 · 0 comments
Open

Constraint check fails for .0 patch prereleases #78

johanneskra opened this issue Feb 23, 2023 · 0 comments

Comments

@johanneskra
Copy link

johanneskra commented Feb 23, 2023

I think I have found a bug in the constraint check for .0 patch prereleases.

An example for this can be found in the Go Playground https://go.dev/play/p/LShjC5F37TT or in the main.go:

main.go (expand)
package main

import (
  "fmt"

  "github.com/blang/semver/v4"
)

func main() {
  constraint := "0.49.x"
  versionConstraint, err := semver.ParseRange(constraint)
  if err != nil {
  	return
  }

  versions := []string{
  	"0.49.0-alpha",
  	"0.49.1-alpha",
  	"0.49.0",
  	"0.49.1",
  }

  for _, ver := range versions {
  	parsedVersion, err := semver.Parse(ver)
  	if err != nil {
  		return
  	}

  	fmt.Printf("%v becomes:\n %#v \n", ver, parsedVersion)
  	fmt.Printf(" Major: %d\n", parsedVersion.Major)
  	fmt.Printf(" Minor: %d\n", parsedVersion.Minor)
  	fmt.Printf(" Patch: %d\n", parsedVersion.Patch)
  	fmt.Printf(" Pre: %s\n", parsedVersion.Pre)
  	fmt.Printf(" Build: %s\n", parsedVersion.Build)

  	didMatch := "false"
  	if versionConstraint(parsedVersion) {
  		didMatch = "true"
  	}

  	fmt.Printf(" => constraint %v matched for %v: %v \n\n", constraint, ver, didMatch)
  }

}

The output of this is:

0.49.0-alpha becomes:
 semver.Version{Major:0x0, Minor:0x31, Patch:0x0, Pre:[]semver.PRVersion{semver.PRVersion{VersionStr:"alpha", VersionNum:0x0, IsNum:false}}, Build:[]string(nil)} 
 Major: 0
 Minor: 49
 Patch: 0
 Pre: [alpha]
 Build: []
 => constraint 0.49.x matched for 0.49.0-alpha: false // ❌ this seems to be a bug

0.49.1-alpha becomes:
 semver.Version{Major:0x0, Minor:0x31, Patch:0x1, Pre:[]semver.PRVersion{semver.PRVersion{VersionStr:"alpha", VersionNum:0x0, IsNum:false}}, Build:[]string(nil)} 
 Major: 0
 Minor: 49
 Patch: 1
 Pre: [alpha]
 Build: []
 => constraint 0.49.x matched for 0.49.1-alpha: true  // ✅ as expected 

0.49.0 becomes:
 semver.Version{Major:0x0, Minor:0x31, Patch:0x0, Pre:[]semver.PRVersion(nil), Build:[]string(nil)} 
 Major: 0
 Minor: 49
 Patch: 0
 Pre: []
 Build: []
 => constraint 0.49.x matched for 0.49.0: true // ✅ as expected 

0.49.1 becomes:
 semver.Version{Major:0x0, Minor:0x31, Patch:0x1, Pre:[]semver.PRVersion(nil), Build:[]string(nil)} 
 Major: 0
 Minor: 49
 Patch: 1
 Pre: []
 Build: []
 => constraint 0.49.x matched for 0.49.1: true // ✅ as expected 

According to this SemVer check, that's incorrect: https://jubianchi.github.io/semver-check/#/0.49.x/0.49.0-alpha.

@johanneskra johanneskra changed the title Contraint check fails for .0 patch prereleases Constraint check fails for .0 patch prereleases Feb 24, 2023
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