mirror of
https://github.com/makeworld-the-better-one/amfora.git
synced 2024-09-11 14:55:51 +03:00
✨ Allow relative URLs in bottom bar
This commit is contained in:
parent
621a2908cd
commit
ef0675fc0b
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user