From 8a4d2d6f7fc2f9ab5ea488d4b4ba76313862fbc0 Mon Sep 17 00:00:00 2001 From: lalyos Date: Mon, 11 Aug 2014 23:36:09 +0200 Subject: [PATCH 1/2] Add test case for identical short and long version numbers Signed-off-by: Lajos Papp --- pkg/version/version_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/version/version_test.go b/pkg/version/version_test.go index 27c0536c2f..c02ec40fcb 100644 --- a/pkg/version/version_test.go +++ b/pkg/version/version_test.go @@ -12,6 +12,8 @@ func assertVersion(t *testing.T, a, b string, result int) { func TestCompareVersion(t *testing.T) { assertVersion(t, "1.12", "1.12", 0) + assertVersion(t, "1.0.0", "1", 0) + assertVersion(t, "1", "1.0.0", 0) assertVersion(t, "1.05.00.0156", "1.0.221.9289", 1) assertVersion(t, "1", "1.0.1", -1) assertVersion(t, "1.0.1", "1", 1) From 58ef92f89e5c6637506d2d03784daba50e82d7ff Mon Sep 17 00:00:00 2001 From: lalyos Date: Mon, 11 Aug 2014 23:40:35 +0200 Subject: [PATCH 2/2] Fix equal short-long version number comparison Signed-off-by: Lajos Papp --- pkg/version/version.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/version/version.go b/pkg/version/version.go index 5ff9d2ed2a..6a7d63544b 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -12,9 +12,17 @@ func (me Version) compareTo(other Version) int { meTab = strings.Split(string(me), ".") otherTab = strings.Split(string(other), ".") ) - for i, s := range meTab { + + max := len(meTab) + if len(otherTab) > max { + max = len(otherTab) + } + for i := 0; i < max; i++ { var meInt, otherInt int - meInt, _ = strconv.Atoi(s) + + if len(meTab) > i { + meInt, _ = strconv.Atoi(meTab[i]) + } if len(otherTab) > i { otherInt, _ = strconv.Atoi(otherTab[i]) } @@ -25,9 +33,6 @@ func (me Version) compareTo(other Version) int { return -1 } } - if len(otherTab) > len(meTab) { - return -1 - } return 0 }