Skip to content

Commit

Permalink
Merge pull request #70 from Masterminds/fix/0-range
Browse files Browse the repository at this point in the history
Fix the handling of pre-releases and the 0.0.0 release edge case
  • Loading branch information
mattfarina authored Apr 10, 2018
2 parents 8d82589 + c50dfe5 commit 872a903
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
20 changes: 0 additions & 20 deletions constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,6 @@ func constraintNotEqual(v *Version, c *constraint) bool {

func constraintGreaterThan(v *Version, c *constraint) bool {

// An edge case the constraint is 0.0.0 and the version is 0.0.0-someprerelease
// exists. This that case.
if !isNonZero(c.con) && isNonZero(v) {
return true
}

// If there is a pre-release on the version but the constraint isn't looking
// for them assume that pre-releases are not compatible. See issue 21 for
// more details.
Expand Down Expand Up @@ -271,11 +265,6 @@ func constraintLessThan(v *Version, c *constraint) bool {
}

func constraintGreaterThanEqual(v *Version, c *constraint) bool {
// An edge case the constraint is 0.0.0 and the version is 0.0.0-someprerelease
// exists. This that case.
if !isNonZero(c.con) && isNonZero(v) {
return true
}

// If there is a pre-release on the version but the constraint isn't looking
// for them assume that pre-releases are not compatible. See issue 21 for
Expand Down Expand Up @@ -415,12 +404,3 @@ func rewriteRange(i string) string {

return o
}

// Detect if a version is not zero (0.0.0)
func isNonZero(v *Version) bool {
if v.Major() != 0 || v.Minor() != 0 || v.Patch() != 0 || v.Prerelease() != "" {
return true
}

return false
}
16 changes: 14 additions & 2 deletions constraints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,21 @@ func TestConstraintCheck(t *testing.T) {
{"<=1.1", "0.1.0", true},
{"<=1.1", "1.1.0", true},
{"<=1.1", "1.1.1", false},
{">0", "0.0.1-alpha", true},
{">=0", "0.0.1-alpha", true},
{">0", "0", false},
{">0", "0.0.1-alpha", false},
{">0.0", "0.0.1-alpha", false},
{">0-0", "0.0.1-alpha", true},
{">0.0-0", "0.0.1-alpha", true},
{">0", "0.0.0-alpha", false},
{">0-0", "0.0.0-alpha", true},
{">=0", "0.0.1-alpha", false},
{">=0.0", "0.0.1-alpha", false},
{">=0-0", "0.0.1-alpha", true},
{">=0.0-0", "0.0.1-alpha", true},
{">=0", "0.0.0-alpha", false},
{">=0-0", "0.0.0-alpha", true},
{"<0", "0.0.0-alpha", false},
{"<0-z", "0.0.0-alpha", true},
{">=0", "0", true},
{"=0", "1", false},
}
Expand Down

0 comments on commit 872a903

Please sign in to comment.