Solves issue where 0 crashes program

This commit is contained in:
sloumdrone 2019-05-26 10:06:43 -07:00
parent 6a524d9f70
commit 30bbfa7161
1 changed files with 5 additions and 2 deletions

View File

@ -157,6 +157,9 @@ func simpleCommand(a string) error {
} }
func goToURL(u string) error { func goToURL(u string) error {
if num, _ := regexp.MatchString(`^-?\d+.?\d*$`, u); num {
return goToLink(u)
}
quickMessage("Loading...", false) quickMessage("Loading...", false)
v, err := gopher.Visit(u, options["openhttp"]) v, err := gopher.Visit(u, options["openhttp"])
if err != nil { if err != nil {
@ -182,10 +185,10 @@ func goToURL(u string) error {
} }
func goToLink(l string) error { func goToLink(l string) error {
if num, _ := regexp.MatchString(`^\d+$`, l); num && history.Length > 0 { if num, _ := regexp.MatchString(`^-?\d+$`, l); num && history.Length > 0 {
linkcount := len(history.Collection[history.Position].Links) linkcount := len(history.Collection[history.Position].Links)
item, _ := strconv.Atoi(l) item, _ := strconv.Atoi(l)
if item <= linkcount { if item <= linkcount && item > 0 {
linkurl := history.Collection[history.Position].Links[item-1] linkurl := history.Collection[history.Position].Links[item-1]
quickMessage("Loading...", false) quickMessage("Loading...", false)
v, err := gopher.Visit(linkurl, options["openhttp"]) v, err := gopher.Visit(linkurl, options["openhttp"])