Allow relative URLs in bottom bar

This commit is contained in:
Chloe Kudryavtsev 2020-08-18 17:32:53 -04:00
parent 621a2908cd
commit ef0675fc0b
1 changed files with 6 additions and 15 deletions

View File

@ -3,7 +3,6 @@ package display
import ( import (
"fmt" "fmt"
"net/url" "net/url"
"path"
"strconv" "strconv"
"strings" "strings"
@ -127,27 +126,19 @@ func Init() {
reset() reset()
return return
} }
if query == ".." && tabs[tab].hasContent() { if query[0] == '.' && tabs[tab].hasContent() { // relative url
// Go up a directory current, err := url.Parse(tabs[tab].page.Url)
parsed, err := url.Parse(tabs[tab].page.Url)
if err != nil { if err != nil {
// This shouldn't occur // This shouldn't occur
return return
} }
if parsed.Path == "/" { target, err := current.Parse(query)
// Can't go up further if err != nil {
// invalid relative url
reset() reset()
return return
} }
URL(target.String())
// Ex: /test/foo/ -> /test/foo//.. -> /test -> /test/
parsed.Path = path.Clean(parsed.Path+"/..") + "/"
if parsed.Path == "//" {
// Fix double slash that occurs at domain root
parsed.Path = "/"
}
parsed.RawQuery = "" // Remove query
URL(parsed.String())
return return
} }