update go-version

The latest go-version update properly handles pre-release versions in
constraints.
This commit is contained in:
James Bardin 2018-03-28 14:07:39 -04:00 committed by Martin Atkins
parent 618883596a
commit 398a6ef31a
2 changed files with 35 additions and 7 deletions

View File

@ -2,6 +2,7 @@ package version
import ( import (
"fmt" "fmt"
"reflect"
"regexp" "regexp"
"strings" "strings"
) )
@ -113,6 +114,26 @@ func parseSingle(v string) (*Constraint, error) {
}, nil }, nil
} }
func prereleaseCheck(v, c *Version) bool {
switch vPre, cPre := v.Prerelease() != "", c.Prerelease() != ""; {
case cPre && vPre:
// A constraint with a pre-release can only match a pre-release version
// with the same base segments.
return reflect.DeepEqual(c.Segments64(), v.Segments64())
case !cPre && vPre:
// A constraint without a pre-release can only match a version without a
// pre-release.
return false
case cPre && !vPre:
// OK, except with the pessimistic operator
case !cPre && !vPre:
// OK
}
return true
}
//------------------------------------------------------------------- //-------------------------------------------------------------------
// Constraint functions // Constraint functions
//------------------------------------------------------------------- //-------------------------------------------------------------------
@ -126,22 +147,27 @@ func constraintNotEqual(v, c *Version) bool {
} }
func constraintGreaterThan(v, c *Version) bool { func constraintGreaterThan(v, c *Version) bool {
return v.Compare(c) == 1 return prereleaseCheck(v, c) && v.Compare(c) == 1
} }
func constraintLessThan(v, c *Version) bool { func constraintLessThan(v, c *Version) bool {
return v.Compare(c) == -1 return prereleaseCheck(v, c) && v.Compare(c) == -1
} }
func constraintGreaterThanEqual(v, c *Version) bool { func constraintGreaterThanEqual(v, c *Version) bool {
return v.Compare(c) >= 0 return prereleaseCheck(v, c) && v.Compare(c) >= 0
} }
func constraintLessThanEqual(v, c *Version) bool { func constraintLessThanEqual(v, c *Version) bool {
return v.Compare(c) <= 0 return prereleaseCheck(v, c) && v.Compare(c) <= 0
} }
func constraintPessimistic(v, c *Version) bool { func constraintPessimistic(v, c *Version) bool {
// Using a pessimistic constraint with a pre-release, restricts versions to pre-releases
if !prereleaseCheck(v, c) || (c.Prerelease() != "" && v.Prerelease() == "") {
return false
}
// If the version being checked is naturally less than the constraint, then there // If the version being checked is naturally less than the constraint, then there
// is no way for the version to be valid against the constraint // is no way for the version to be valid against the constraint
if v.LessThan(c) { if v.LessThan(c) {

8
vendor/vendor.json vendored
View File

@ -1815,10 +1815,12 @@
"revision": "36289988d83ca270bc07c234c36f364b0dd9c9a7" "revision": "36289988d83ca270bc07c234c36f364b0dd9c9a7"
}, },
{ {
"checksumSHA1": "9w1ZtxhdB/J0qqNPJQNNI/ZTwwE=", "checksumSHA1": "4+PK0yd1prnC11PETgrXPzHyct4=",
"path": "github.com/hashicorp/go-version", "path": "github.com/hashicorp/go-version",
"revision": "4fe82ae3040f80a03d04d2cccb5606a626b8e1ee", "revision": "23480c0665776210b5fbbac6eaaee40e3e6a96b7",
"revisionTime": "2017-11-29T15:08:20Z" "revisionTime": "2018-03-22T23:02:33Z",
"version": "master",
"versionExact": "master"
}, },
{ {
"checksumSHA1": "o3XZZdOnSnwQSpYw215QV75ZDeI=", "checksumSHA1": "o3XZZdOnSnwQSpYw215QV75ZDeI=",