1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-22 20:37:05 +00:00

file-server: fix ShowList on root dir

Former-commit-id: 6795382235d76942bcfd31ecc0b4ab02ecb85a8a
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-07-05 05:39:48 +03:00
parent 0a1b500c8b
commit 57dc64625d
12 changed files with 142 additions and 131 deletions

View File

@@ -316,10 +316,22 @@ func FileServer(directory string, opts ...DirOptions) context.Handler {
if d.IsDir() {
name += "/"
}
upath := ""
// if ctx.Path() == "/" && dirName == strings.TrimPrefix(directory, "./") {
if ctx.Path() == "/" {
upath = ctx.GetCurrentRoute().StaticPath() + "/" + name
} else {
upath = "./" + dirName + "/" + name
}
url := url.URL{
Path: upath,
} // edit here to redirect correctly, standard library misses that.
// name may contain '?' or '#', which must be escaped to remain
// part of the URL path, and not indicate the start of a query
// string or fragment.
url := url.URL{Path: joinPath("./"+dirName, name)} // edit here to redirect correctly, standard library misses that.
_, err = ctx.Writef("<a href=\"%s\">%s</a>\n", url.String(), htmlReplacer.Replace(name))
if err != nil {
return err