Skip to content

Commit

Permalink
fix: getCleanVersion with corrupted version "1" or "1.2" instead "1.2.3"
Browse files Browse the repository at this point in the history
  • Loading branch information
Icaruk committed Aug 2, 2024
1 parent efb90c0 commit 8e33714
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package3.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"node": "20.5.0"
},
"dependencies": {
"@dytesdk/react-ui-kit": "^0.0.1"
"surrealdb.js": "^0.11.1"
},
"volta": {
"node": "20.5.0"
Expand Down
24 changes: 20 additions & 4 deletions pkg/utils/version/getCleanVersion.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
package version

import "regexp"
import (
"regexp"
)

func GetCleanVersion(version string) (string, string) {

if version == "" {
return "", ""
}

re := regexp.MustCompile(`([^0-9]*)(\d+\.\d+\.\d+)(.*)`)
reSubmatch := re.FindStringSubmatch(version)
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]
cleanVersion := reSubmatch[2]
major := reSubmatch[2]
minor := reSubmatch[3]
patch := reSubmatch[4]

if major == "" {
major = "0"
}
if minor == "" {
minor = "0"
}
if patch == "" {
patch = "0"
}

cleanVersion := major + "." + minor + "." + patch

return prefix, cleanVersion
}
10 changes: 10 additions & 0 deletions pkg/utils/version/getCleanVersion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ func TestGetCleanVersion(t *testing.T) {
expectedPrefix: "^",
expectedVersion: "1.2.3",
},
{
version: "^1",
expectedPrefix: "^",
expectedVersion: "1.0.0",
},
{
version: "^1.2",
expectedPrefix: "^",
expectedVersion: "1.2.0",
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit 8e33714

Please sign in to comment.