Skip to content

Commit

Permalink
fix: GetCleanVersion regex
Browse files Browse the repository at this point in the history
  • Loading branch information
Icaruk committed Aug 5, 2024
1 parent ad045e4 commit 89234c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/utils/version/getCleanVersion.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func GetCleanVersion(version string) (string, string) {
return "", ""
}

re := regexp.MustCompile(`([^0-9]*)(\d?)\.?(\d?)\.?(\d?)(.*)`)
re := regexp.MustCompile(`([^0-9]*)(\d*)\.?(\d*)\.?(\d*)(.*)`)
reSubmatch := re.FindStringSubmatch(version) // [0] all, [1] = prefix, [2] = major, [3] = minor, [4] = patch

prefix := reSubmatch[1]
Expand Down
15 changes: 15 additions & 0 deletions pkg/utils/version/getCleanVersion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ func TestGetCleanVersion(t *testing.T) {
expectedPrefix: "^",
expectedVersion: "1.2.3",
},
{
version: "^15.0.0-canary.102",
expectedPrefix: "^",
expectedVersion: "15.0.0",
},
{
version: "^1",
expectedPrefix: "^",
Expand All @@ -45,6 +50,16 @@ func TestGetCleanVersion(t *testing.T) {
expectedPrefix: "^",
expectedVersion: "1.2.0",
},
{
version: "12.34.56",
expectedPrefix: "",
expectedVersion: "12.34.56",
},
{
version: "123.3456",
expectedPrefix: "",
expectedVersion: "123.3456.0",
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit 89234c3

Please sign in to comment.