Initial 'v' in versions should not be compared on (fixes #980)

This commit is contained in:
Jakob Borg 2014-11-17 18:49:51 +04:00
parent f66c7dc09c
commit 70d8903d3c
2 changed files with 8 additions and 0 deletions

View File

@ -153,6 +153,10 @@ func CompareVersions(a, b string) int {
// Split a version into parts.
// "1.2.3-beta.2" -> []int{1, 2, 3}, []interface{}{"beta", 2}
func versionParts(v string) ([]int, []interface{}) {
if strings.HasPrefix(v, "v") || strings.HasPrefix(v, "V") {
// Strip initial 'v' or 'V' prefix if present.
v = v[1:]
}
parts := strings.SplitN(v, "+", 2)
parts = strings.SplitN(parts[0], "-", 2)
fields := strings.Split(parts[0], ".")

View File

@ -42,6 +42,10 @@ var testcases = []struct {
{"1.0.0+45", "1.0.0+23-dev-foo", 0},
{"1.0.0-beta.23+45", "1.0.0-beta.23+23-dev-foo", 0},
{"1.0.0-beta.3+99", "1.0.0-beta.24+0", -1},
{"v1.1.2", "1.1.2", 0},
{"v1.1.2", "V1.1.2", 0},
{"1.1.2", "V1.1.2", 0},
}
func TestCompareVersions(t *testing.T) {