1
0
mirror of https://github.com/makew0rld/amfora.git synced 2024-12-04 14:46:29 -05:00

Merge pull request #72 from CosmicToast/relurl

 Allow relative URLs in bottom bar
This commit is contained in:
makeworld 2020-08-18 19:48:40 -04:00 committed by GitHub
commit 5ea97f3a8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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() {
// Go up a directory // Relative url
parsed, err := url.Parse(tabs[tab].page.Url) current, 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 {
reset() // Invalid relative url
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
} }