Skip to content

Commit e0fe490

Browse files
author
Graren
committed
Fixed comparison in exceeds latest
Tiny fix, I'm sure it can be beautified or refactored
1 parent 496971a commit e0fe490

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/nvm.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"./nvm/arch"
1313
"./nvm/file"
1414
"./nvm/node"
15+
"strconv"
1516
"github.com/olekukonko/tablewriter"
1617
)
1718

@@ -144,12 +145,19 @@ func CheckVersionExceedsLatest(version string) bool{
144145
re := regexp.MustCompile("node-v(.+)+msi")
145146
reg := regexp.MustCompile("node-v|-x.+")
146147
latest := reg.ReplaceAllString(re.FindString(content),"")
147-
148-
if version <= latest {
149-
return false
150-
} else {
151-
return true
148+
var vArr = strings.Split(version,".")
149+
var lArr = strings.Split(latest, ".")
150+
for index := range lArr {
151+
lat,_ := strconv.Atoi(lArr[index])
152+
ver,_ := strconv.Atoi(vArr[index])
153+
//Should check for valid input (checking for conversion errors) but this tool is made to trust the user
154+
if ver < lat {
155+
return false
156+
} else if ver > lat {
157+
return true
158+
}
152159
}
160+
return false
153161
}
154162

155163
func install(version string, cpuarch string) {
@@ -197,7 +205,6 @@ func install(version string, cpuarch string) {
197205
fmt.Println("Node.js v"+version+" is not yet released or available.")
198206
return
199207
}
200-
201208
if cpuarch == "64" && !web.IsNode64bitAvailable(version) {
202209
fmt.Println("Node.js v"+version+" is only available in 32-bit.")
203210
return

0 commit comments

Comments
 (0)