diff --git a/README.md b/README.md index dade530..1e7fb75 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,8 @@ Ranges can be combined by both AND and OR - `>1.0.0 <2.0.0 || >3.0.0 !4.2.1` would match `1.2.3`, `1.9.9`, `3.1.1`, but not `4.2.1`, `2.1.1` +Ranges operating on pre release versions can produce counter intuitive results. One might expect the range `>=1.0.0 <2.0.0` to always match versions with major version `1`. However, pre release versions are less than the release version, so `1.0.0-build.1` will not match, while `2.0.0-build.1` will. If a range will operate on pre release versions, be sure to include a pre release value of `0` making the desired range `>=1.0.0-0 <2.0.0-0`. Alternatively, the range `1.x` will match all versions with major version `1`. + Range usage: ``` diff --git a/examples/main.go b/examples/main.go index 72eefbe..b51f819 100644 --- a/examples/main.go +++ b/examples/main.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/k14s/semver" + "github.com/carvel-dev/semver" ) func main() { diff --git a/v4/examples/main.go b/v4/examples/main.go index 64c90d1..bc73523 100644 --- a/v4/examples/main.go +++ b/v4/examples/main.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/k14s/semver/v4" + "github.com/carvel-dev/semver/v4" ) func main() { diff --git a/v4/range.go b/v4/range.go index 95f7139..cee7b4b 100644 --- a/v4/range.go +++ b/v4/range.go @@ -67,8 +67,8 @@ func (vr *versionRange) rangeFunc() Range { // Range represents a range of versions. // A Range can be used to check if a Version satisfies it: // -// range, err := semver.ParseRange(">1.0.0 <2.0.0") -// range(semver.MustParse("1.1.1") // returns true +// range, err := semver.ParseRange(">1.0.0 <2.0.0") +// range(semver.MustParse("1.1.1") // returns true type Range func(Version) bool // OR combines the existing Range with another Range using logical OR. @@ -108,7 +108,7 @@ func (rf Range) AND(f Range) Range { // // Ranges can be combined by both AND and OR // -// - `>1.0.0 <2.0.0 || >3.0.0 !4.2.1` would match `1.2.3`, `1.9.9`, `3.1.1`, but not `4.2.1`, `2.1.1` +// - `>1.0.0 <2.0.0 || >3.0.0 !4.2.1` would match `1.2.3`, `1.9.9`, `3.1.1`, but not `4.2.1`, `2.1.1` func ParseRange(s string) (Range, error) { parts := splitAndTrim(s) orParts, err := splitORParts(parts) @@ -269,10 +269,10 @@ func createVersionFromWildcard(vStr string) string { // handle 1.x if len(parts) == 2 { - return vStr2 + ".0" + vStr2 = vStr2 + ".0" } - return vStr2 + return vStr2 + "-0" } // incrementMajorVersion will increment the major version diff --git a/v4/range_test.go b/v4/range_test.go index 2f44de4..6d20759 100644 --- a/v4/range_test.go +++ b/v4/range_test.go @@ -218,8 +218,8 @@ func TestCreateVersionFromWildcard(t *testing.T) { i string s string }{ - {"1.2.x", "1.2.0"}, - {"1.x", "1.0.0"}, + {"1.2.x", "1.2.0-0"}, + {"1.x", "1.0.0-0"}, } for _, tc := range tests { @@ -272,18 +272,18 @@ func TestExpandWildcardVersion(t *testing.T) { o [][]string }{ {[][]string{{"foox"}}, nil}, - {[][]string{{">=1.2.x"}}, [][]string{{">=1.2.0"}}}, - {[][]string{{"<=1.2.x"}}, [][]string{{"<1.3.0"}}}, - {[][]string{{">1.2.x"}}, [][]string{{">=1.3.0"}}}, - {[][]string{{"<1.2.x"}}, [][]string{{"<1.2.0"}}}, - {[][]string{{"!=1.2.x"}}, [][]string{{"<1.2.0", ">=1.3.0"}}}, - {[][]string{{">=1.x"}}, [][]string{{">=1.0.0"}}}, - {[][]string{{"<=1.x"}}, [][]string{{"<2.0.0"}}}, - {[][]string{{">1.x"}}, [][]string{{">=2.0.0"}}}, - {[][]string{{"<1.x"}}, [][]string{{"<1.0.0"}}}, - {[][]string{{"!=1.x"}}, [][]string{{"<1.0.0", ">=2.0.0"}}}, - {[][]string{{"1.2.x"}}, [][]string{{">=1.2.0", "<1.3.0"}}}, - {[][]string{{"1.x"}}, [][]string{{">=1.0.0", "<2.0.0"}}}, + {[][]string{{">=1.2.x"}}, [][]string{{">=1.2.0-0"}}}, + {[][]string{{"<=1.2.x"}}, [][]string{{"<1.3.0-0"}}}, + {[][]string{{">1.2.x"}}, [][]string{{">=1.3.0-0"}}}, + {[][]string{{"<1.2.x"}}, [][]string{{"<1.2.0-0"}}}, + {[][]string{{"!=1.2.x"}}, [][]string{{"<1.2.0-0", ">=1.3.0-0"}}}, + {[][]string{{">=1.x"}}, [][]string{{">=1.0.0-0"}}}, + {[][]string{{"<=1.x"}}, [][]string{{"<2.0.0-0"}}}, + {[][]string{{">1.x"}}, [][]string{{">=2.0.0-0"}}}, + {[][]string{{"<1.x"}}, [][]string{{"<1.0.0-0"}}}, + {[][]string{{"!=1.x"}}, [][]string{{"<1.0.0-0", ">=2.0.0-0"}}}, + {[][]string{{"1.2.x"}}, [][]string{{">=1.2.0-0", "<1.3.0-0"}}}, + {[][]string{{"1.x"}}, [][]string{{">=1.0.0-0", "<2.0.0-0"}}}, } for _, tc := range tests { @@ -461,6 +461,22 @@ func TestParseRange(t *testing.T) { {"1.2.6", false}, {"1.3.0", true}, }}, + {"1.3.x", []tv{ + {"1.2.0", false}, + {"1.3.0-0", true}, + {"1.3.0", true}, + {"1.3.9", true}, + {"1.4.0-0", false}, + {"1.4.0", false}, + }}, + {"2.x", []tv{ + {"1.9.9", false}, + {"2.0.0-0", true}, + {"2.0.0", true}, + {"2.9.9", true}, + {"3.0.0-0", false}, + {"3.0.0", false}, + }}, // Combined Expressions {">1.2.2 <1.2.4 || >=2.0.0", []tv{ {"1.2.2", false},