From 8318a6b1cc340e0d657808d543bb2e942ec3e4d7 Mon Sep 17 00:00:00 2001 From: mengqi <5b5f7426@gmail.com> Date: Mon, 5 Oct 2015 12:18:24 +0800 Subject: [PATCH] fix #4: unesacpe parent directory before getting it's modification time --- server/dirlist.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/server/dirlist.go b/server/dirlist.go index 66c1e77..4b7b1e2 100644 --- a/server/dirlist.go +++ b/server/dirlist.go @@ -148,14 +148,21 @@ func (this *RanServer) listDir(w http.ResponseWriter, c *context) (size int64, e name += "/" } name = html.EscapeString(name) - url := url.URL{Path: name} + fileUrl:= url.URL{Path: name} // write parent dir if n == 0 && c.cleanPath != "/" { parent := c.parent() + // unescape parent before get it's modification time + var parentUnescape string + parentUnescape, err = url.QueryUnescape(parent) + if err != nil { + return + } + var info os.FileInfo - info, err = os.Stat(filepath.Join(this.config.Root, parent)) + info, err = os.Stat(filepath.Join(this.config.Root, parentUnescape)) if err != nil { return } @@ -163,7 +170,7 @@ func (this *RanServer) listDir(w http.ResponseWriter, c *context) (size int64, e files = append(files, dirListFiles{Name:"[..]", Url:parent, ModTime:info.ModTime()}) } - files = append(files, dirListFiles{Name:name, Url:url.String(), Size:i.Size(), ModTime:i.ModTime()}) + files = append(files, dirListFiles{Name:name, Url:fileUrl.String(), Size:i.Size(), ModTime:i.ModTime()}) } data := dirList{ Title: title, Files: files}