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

View File

@ -3,7 +3,6 @@ package display
import (
"fmt"
"net/url"
"path"
"strconv"
"strings"
@ -127,27 +126,19 @@ func Init() {
reset()
return
}
if query == ".." && tabs[tab].hasContent() {
// Go up a directory
parsed, err := url.Parse(tabs[tab].page.Url)
if query[0] == '.' && tabs[tab].hasContent() { // relative url
current, err := url.Parse(tabs[tab].page.Url)
if err != nil {
// This shouldn't occur
return
}
if parsed.Path == "/" {
// Can't go up further
target, err := current.Parse(query)
if err != nil {
// invalid relative url
reset()
return
}
// 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())
URL(target.String())
return
}